Here's a table to get you started on how to think about the different notations:
decimal hex binaryDecimal to binary conversion:
0 0 0
1 1 1
2 2 10
3 3 11
4 4 100
5 5 101
6 6 110
7 7 111
8 8 1000
9 9 1001
10 A 1010
11 B 1011
12 C 1100
13 D 1101
14 E 1110
15 F 1111
16 10 10000
17 11 10001
18 12 10010
19 13 10011
20 14 10100
. . .
. . .
. . .
To do decimal to binary conversion, one algorithm you can use is to simply divide the decimal number by two and continue recording the remainder until you get to a quotient of zero. For example, suppose I began with the number 11:
11/2 = 5 Remainder: 1The binary number you get out of this is simply 1011. You can verify that this is the right number by converting the binary back to decimal as follows:
5/2 = 2 Remainder: 1
2/2 = 1 Remainder: 0
1/2 = 0 Remainder: 1
2^3 2^2 2^1 2^0Hex conversions:
8 4 2 1
------------------
1 0 1 18 + 0 + 2 + 1 = 11!
Given a binary number, you can easily convert to the hexadecimal representation by grouping the binary number into groups of 4 digits. The possible values for the hex number are up in the table above. Given a decimal number, you can use a similar algorithm to the one above for binary conversions, repeatedly dividing by 16, remembering that the remainder can be represented by the digits 0 -> 9 and the letters A -> F as shown in the table above.
Example Conversion:
73289 (decimal) = 0001 0001 1110 0100 1001 (binary) = 0x11E49 (hex)
Note: hexadecimal numbers are often expressed beginning with a 0x
Questions:
Convert the following decimal numbers to both binary and hex:
1) 32
2) 5236
3) 21387
Convert the following hex numbers to binary and decimal:
1) 0x67A0
2) 0x002AC
3) 0x70AFF
Convert the following binary numbers to hex and decimal:
1) 000111010
2) 100100101
3) 001001111
Step 1: Begin by writing out 34 in binary form:
00100010Step 2: Invert all of the digits:
11011101Step 3: Add 1:
11011110Presto! You have your negative number. So -34 is expressed as 11011110. That means any number with a 1 in its most significant bit (leftmost) is negative. Likewise, given a two's complement number, you can easily find out what it represents by inverting the digits back and adding a 1.
Questions: