Question: Write a program that takes an integer from the user and converts it into its proper binary and hexadecimal representation using a LIFO structure. Precondition:
Write a program that takes an integer from the user and converts it into its proper binary and hexadecimal representation using a LIFO structure.
Precondition: The decimal numbers will be integers and positive.
Binary
|
| 2^3 | 2^2 | 2^1 | 2^0 |
|
| 8 | 4 | 2 | 1 |
| 10 | 1 | 0 | 1 | 0 |
10 mod 2 =0, 10/2=5
5 mod 2 =1, 5/2=2
2 mod 2=0, 2/2=1
1 mod 2 =1, 1 /2=0
Hexadecimal
Note that in the hexadecimal number system, the numbers are in the following sequence
0 1 2 3 4 5 6 7 8 9 A B C D E F
The decimal equivalent is
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
To convert the decimal number 65 into its hexadecimal equivalent:
|
| 16^3 | 16^2 | 16^1 | 16^0 |
|
| 4096 | 256 | 16 | 1 |
| 65 |
|
| 4 | 1 |
65 mod 16=1 65/16=4
4 mod 16=4 4/16=0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
