Results 1 to 2 of 2
- 11-19-2013, 11:00 PM #1Member
- Join Date
- Nov 2013
- Rep Power
Program Using Arrays To Conver Binary to Decimal and Decimal to Binary.
I am in a AP Computer Science class and have an assignment that I have NO CLUE how to do. I will post the instructions below. Can someone throw together a fast code that I can base mine off of please.
In this project, we’re going to revisit the concept of binary numbers and base conversions with the use of arrays. The goal
is going to be to design a program that will ask the user if they would like to convert from binary to decimal (or vice versa),
and the program will generate the appropriate output.
Create a Java Project in Eclipse called Binary Numbers. Create a class called BinaryNumbers, and make sure it has
the main method.
There are several algorithms for converting a decimal number to binary, but the one most commonly used seems to follow
Decimal Number: 170
Largest power of two not exceeding the decimal number: 128
Is 128 in 170? Yep! Put a 1 in that place and subtract 128 => 42
Is 64 in 42? Nope.
Is 32 in 42? Yep! Put a 1 in that place and subtract 32 => 10
Is 16 in 10? Nope.
Is 8 in 10? Yep! Put a 1 in that place and subtract 8 => 2
Is 4 in 2? Nope.
Is 2 in 2? Yep! Put a 1 in that place and subtract 2 => 0
We’re down to zero left, so we must be done!
- 11-19-2013, 11:25 PM #2
Re: Program Using Arrays To Conver Binary to Decimal and Decimal to Binary.
What have you tried? - Matt Gemmell
Post your code and specific questions about the problems you are having?If you don't understand my response, don't ignore it, ask a question.
- By Nightcrawler in forum New To JavaReplies: 3Last Post: 03-05-2012, 03:45 AM
- By HandMeTheBacon in forum New To JavaReplies: 0Last Post: 09-13-2011, 03:35 AM
- By irnie1994 in forum JCreatorReplies: 5Last Post: 08-25-2011, 07:32 PM
- By matejm1994 in forum New To JavaReplies: 3Last Post: 12-26-2010, 10:59 AM