4.2 Number Bases in Positional Systems
Recall: Decimal (base 10) System 10000 1000 100 10 1 104 103 102 101 4 3 5 2 4 x 10000 3 x1000 5 x100 1 x10 2 = 43512 Uses 10 digits (symbols): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Each position implies power of 10
Binary (base 2) System Computer signals in terms of ‘yes’/’no’, ‘on’/’off’, ‘high voltage’/’low voltage’, 1/0. Computer data storage also in terms of ‘on’/’off’, ‘north pole’/’south pole’, 1/0. Binary system uses 2 symbols: 0, 1 E.g., 1two = 1ten 10two = 2ten 11two = 3ten 100two = 4ten 101two = 5ten
Binary (base 2) System 64 +0 +1 = 65dec Uses 2 digits (symbols): 0, 1 Each position implies power of 2
Binary (base 2) System Decimal Binary 1 2 10 3 11 4 100 5 101 6 110 7 111 8 1000 9 1001 1010 1011 12 1100 13 1101
Converting Binary to Decimal Express the following binary notation in decimal notation. 0110binary = (0 x 23) + (1 x 22) + (1 x 21) + (0 x 20) = 0 + 4 + 2 + 0 = 6 1111binary = (1 x 23) + (1 x 22) + (1 x 21) + (1 x 20) = 8 + 4 + 2 + 1 = 15
Your Turn 111binary = (1 x 22) + (1 x 21) + (0 x 20) = 4 + 2 + 1 = 7 Express the following binary notation in decimal notation. 111binary = (1 x 22) + (1 x 21) + (0 x 20) = 4 + 2 + 1 = 7 10001binary = (1 x 24) + (0 x 23) + (0 x 22) + (0 x 21) + (1 x 20) = 16 + 0 + 0 + 0 + 1 = 17
Hexadecimal Notation (base 16) C++ Code Find the gcd of two numbers E.g., given: 12 and 36 gcd = 12
Computer Program Code Machine Language Code (What? No binary code?) Hexadecimal Notation can serve as a short hand for Binary Notation. In the last line: 8 B 4 5 1000 1101 0100 0101 A C 5 0 1100 1110 0101 0000 F F D 6 1111 1111 1101 0110
Hexadecimal (base 16) Notation Uses 16 symbols: E.g., 2Bhexadecimal = 43ten A3hexadecimal = 163ten Decimal 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Hexadec A B C D E F
Hexadecimal (base 16) Notation 4096 256 16 1 163 162 161 160 3 A C 2 3 x 4096 10 x 256 12 x 16 2 12288 2560 192 2 = 15042dec Uses 16 digits (symbols): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F Each position implies power of 16
Converting Hexadecimal to Decimal Notation Converting Hexadecimal to Decimal Notation Dec Hex 1 2 3 4 5 6 7 8 9 10 A 11 B 12 C 13 D 14 E 15 F Convert from hexadecimal to decimal notation: 2Bhex Recall: Pos. val. 161 160 16 1 Digit 2 B Dec. val. (2 x 16) + (11 x 1) 32 + 11 = 43dec A3hex (10 x 16) + (3 x 1) 160 + 3 = 163dec
Your Turn Convert from hexadecimal to decimal notation: 8B hex 1 2 3 4 5 6 7 8 9 10 A 11 B 12 C 13 D 14 E 15 F Convert from hexadecimal to decimal notation: 8B hex Recall: Pos. val. 161 160 16 1 Digit 8 B Dec. val. (8 x 16) + (11 x 1) 128 + 11 = 138dec 45 hex (4 x 16) + (5 x 1) 64 + 5 = 69dec
Converting Hexadecimal to Decimal Notation Converting Hexadecimal to Decimal Notation (15 x 256+ (15 x 16) + (15 x 1) = 3840 + 240 + 15 = 3095 Find the decimal numeral for the following hex numeral. 12A FFF (15 x 256+ (15 x 16) + (15 x 1) = 3840 + 240 + 15 = 3095 Pos val. 162 161 160 256 16 1 Digit 2 A Value 1 x 256 2 x 16 10 x 1 32 10 = 298
Your Turn Convert the Hexadecimal Numeral to Decimal Numeral: 13E. 1 2 3 4 5 6 7 8 9 10 A 11 B 12 C 13 D 14 E 15 F Convert the Hexadecimal Numeral to Decimal Numeral: 13E. Pos val. 162 161 160 256 16 1 Digit 3 E Value 1 x 256 3 x 16 14 x 1 48 14 = 308
How Is Binary Notation Related to Hex Notation? 128 64 32 16 8 4 2 1 27 26 25 24 23 22 21 20 64 +16 +8 +2 = 90ten 16 1 161 160 128 64 32 8 4 2 27 26 25 24 23 22 21 20 5 A 5 x 16 10 x 1 = 90ten
Dec Binary Hex 1 2 10 3 11 4 100 5 101 6 110 7 111 8 1000 9 1001 1010 A 1011 B 12 1100 C 13 1101 D 14 1110 E 15 1111 F Your Turn Convert from binary to hexadecimal 11010110 Binary: 1001 0110 Hex: 9 6 10101011 Binary: 1010 1011 Hex: A B 1011000110001101 Binary: 1011 0001 1000 1101 Hex: B 1 8 C
Your Turn A3 Hex: A3 Binary: 1010 0011 FC Hex: FC Binary: 1111 1100 Dec Binary Hex 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 10 1010 A 11 1011 B 12 1100 C 13 1101 D 14 1110 E 15 1111 F Your Turn Convert from hexadecimal to binary. A3 Hex: A3 Binary: 1010 0011 FC Hex: FC Binary: 1111 1100