Homework 02
Byte Converter
09/19/2017 at 11:55PM
Objective:
Write a program that prompts the user for an 8 bit (a byte) binary number and converts that into a decimal number. For binary conversion look at each of the locations, and using that convert that to a decimal number. Let’s take the byte 01011001 and convert it into a decimal value.
|
Binary Digit |
0 |
1 |
0 |
1 |
1 |
0 |
0 |
1 |
|
Base 2 Representation at this position |
27 |
26 |
25 |
24 |
23 |
22 |
21 |
20 |
|
Decimal Value at this Position |
128 |
64 |
32 |
16 |
8 |
4 |
2 |
1 |
Multiplying each binary digit by the decimal values and summing them you get
0*128+1*64+0*32+1*16+1*8+0*4+0*2+1*1 = 89
Assume the user will only input either 0 or 1 without having the check. Also built in Java methods that does this conversion automatically (such as Integer.parseInt(binaryNumber,2)) WILL NOT be accepted.
Example Dialog:
Enter an 8 bit binary number and I will convert it to decimal
01011001
01011001 in decimal form is 89
Finally:
Upload the .java file to the dropbox