hey guys thanks for the vowel help it worked
i got one other question here.
here is the method/function signature
public int powerOfTwo(int number)
the function should return a number such that number - x is a power of two if number is already a power of two it should return 0.
5 1686
here is the method/function signature
public int powerOfTwo(int number)
the function should return a number such that number - x is a power of two if number is already a power of two it should return 0.
I don't understand the question: what is 'x' and is that dash '-' a minus sign?
If it is then the last phrase is redundant. Sorry for being stupid.
kind regards,
Jos
The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.
Please read the Posting Guidelines and particularly the Coursework Posting Guidelines.
Then when you are ready post a new question in this thread.
MODERATOR
public int powerOfTwo(int number)
{
int base = 2;
for(int i=0;i< Math.pow(base,Integer.MAX_VALUE);i++)
{
int powerOf2 = Math.pow(base,i);
}
}
my apologies for breaking the rules,it won't happen again.as you can see i did attempt but i can only come up with a function which i'm not sure it will give me the powers of two.
I understand x is an arbitrary number which if subtracted from the given number in parameters and one subtracted it should result in a power of two.yes that's a minus sign.
i hope this clears the question cause I'm still struggling with it
Ah, I think I understand your question now, you want a function f(n) such that
x= f(n) where n-x is a power of two. Lets ignore n == 0 for now. Right?
If so, note that every number n can be written as 1xxx...xxx where xxx...xxx
are zero or more random digits. Let x = xxx...xxx then n-x is a power of two
and x is minimal.
Also note that 2^m == 1 << m.
kind regards,
Jos
public int powerOfTwo(int number)
{
int base = 2;
for(int i=0;i< Math.pow(base,Integer.MAX_VALUE);i++)
{
int powerOf2 = Math.pow(base,i);
}
}
You should check with your instructor, but I think using Math.pow defeats the purpose of this exercise. I suspect you're supposed to do the math yourself.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Karen |
last post by:
Most my experience has been with MySQL, so I write queries in terms of
SQL statements. I am using access right now as it is on the machine I
have. I am using the SQL window as I couldn't figure out...
|
by: dsptechie |
last post by:
I wanted to how exactly malloc() function works. I came to know that
malloc() allocates memory only in powers of 2. i.e if asked for say 17
bytes , in the process, it allocates 32 bytes and returns...
|
by: PengYu.UT |
last post by:
Hi All,
For example, I want to declare an array
double array;
Of cause, I can define an macro for the 4th power of
VERY_VERY_VERY_LONG_NAME. But I want to know whether there is any build...
|
by: Janice |
last post by:
I got this question from my textbook and I cannot understand the theory.
When a signed positive integer X divided by pow(2,k), the result is shifting
k bits to right and putting w-k bits of 0 from...
|
by: Lisa Simpson |
last post by:
I am writing a program (precisely an image processing filter) which computes
several multiplications of floating-point numbers by constant powers of 2.
This means adding an integer constant to the...
|
by: Camellia |
last post by:
hi all,
I wrote a "table of powers" program and made the 5th power the highest,
but when I tried to run the program I found a problem. Here's the
output:
Integer Square power...
|
by: benbridle38 |
last post by:
Hi,
dont really know much about programming or anything like this.
But basicly in my program i am trying to write the following formula:
http://img8.imageshack.us/img8/4379/fomula.jpg...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |