Weekly Programming Exercise #5
Not graded.
Solution will be discussed on Monday, 10/19.
1) Convert the following decimal numbers into binary numbers in signed 2's complement system.
a. 27
b. -6
c. 64
d. 255
e. -24
2) Binary numbers are inconvenient because they're too long and not easy to read. A hexadecimal notation is a base-16 system frequently used in its place. One hexadecimal digit represents four bits.
Binary Hexadecimal Decimal
1111 F 15
1110 E 14
1101 D 13
1100 C 12
1011 B 11
1010 A 10
1001 9 9
1000 8 8
0111 7 7
0110 6 6
0101 5 5
0100 4 4
0011 3 3
0010 2 2
0001 1 1
0000 0 0
Note that the alphabet A ~ F is used as a digit in the hexadecimal system to express values that are greater or equal to 10.
To print an integer in hexadecimal notation, use %x or %X within printf().
Try to write the decimal numbers from problem 1 in hexadecimal format.
Then use printf to check your answer.