Results 1 to 4 of 4
 11252013, 03:36 AM #1Member
 Join Date
 Nov 2013
 Posts
 22
 Rep Power
 0
Code to find greatest power of 2 below given number
I am working on a project where I need to convert Decimal numbers to binary. In this code I need to write code that finds the greatest power of 2 that is below the number the user entered. I havent made it too far into the code or I would copy paste what I have so far. Anyone have any ideas on what to write to make code that can execute this task?
The given decimal is named int DeciAmount.
 11252013, 03:50 AM #2Senior Member
 Join Date
 Jan 2013
 Location
 Northern Virginia, United States
 Posts
 6,226
 Rep Power
 14
Re: Code to find greatest power of 2 below given number
You still need to copy and paste whatever you have. There are various ways of finding that information out. Using logarithms is one way. Another way is to use a for loop. If you know that then you know how to find the largest power of 2 less than the number.
Regards,
JimThe Java^{TM} Tutorials  SSCCE  Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
 11272013, 04:11 AM #3
Re: Code to find greatest power of 2 below given number
How would you do this if you were doing it on paper? (Hint: What do you notice about binary numbers that are powers of two?)
Get in the habit of using standard Java naming conventions!
 11272013, 08:43 AM #4
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,422
 Blog Entries
 7
 Rep Power
 28
Similar Threads

finding the power to a number then the user inputs a max a min power
By vicu1 in forum New To JavaReplies: 23Last Post: 11202011, 09:07 PM 
Code to convert binary number to base 10 number
By j@y in forum New To JavaReplies: 1Last Post: 10282011, 08:18 AM 
Find max number in 2D array?
By spatel14 in forum New To JavaReplies: 3Last Post: 06302010, 04:27 PM 
find the greatest and lowest number in 2D array
By le_albina@hotmail.com in forum New To JavaReplies: 2Last Post: 03302009, 11:09 PM 
Find all permutations of a number
By matzahboy in forum New To JavaReplies: 6Last Post: 12022008, 03:59 AM
Bookmarks