advertisement

Number Systems – Binary, Octal, Decimal, and Hexadecimal Basic Number Systems and Conversions Binary Base or radix 2 number system Binary digit is called a bit. Numbers are 0 and 1 only. Numbers are expressed as powers of 2. 20 = 1, 21 = 2, 22 = 4, 23 = 8, 24 = 16, 25 = 32, 26 = 64, 27 = 128, 28 = 256, 29 = 512, 210 = 1024, 211 = 2048, 212 = 4096, 212 = 8192, … Conversion of binary to decimal ( base 2 to base 10) Example: convert (110011)2 to decimal = (1 x 25) + (1 x 24) + (0 x 23) + (0 x 22) + (1 x 21) + (1 x 20) = 32 + 16 + 0 + 0 + 2 + 1 = (51)10 Conversion of decimal to binary (base 10 to base 2) Example: convert (51)10 to binary 51 2 = 25 remainder is 1 25 2 = 12 remainder is 1 12 2 = 6 remainder is 0 6 2 = 3 remainder is 0 3 2 = 1 remainder is 1 1 2 = 0 remainder is 1 Answer = 1 1 0 0 1 1 Note: the answer is read from bottom (MSB) to top (LSB) as 1100112 Octal Base or radix 8 number system 1 octal digit is equivalent to 3 bits. Numbers are 0-7. Numbers are expressed as powers of 8. 80 = 1, 81 = 8, 82 = 64, 83 = 512, 84 = 4096. Number Systems - 1 Conversion of octal to decimal ( base 8 to base 10) Example: convert (632)8 to decimal = (6 x 82) + (3 x 81) + (2 x 80) = (6 x 64) + (3 x 8) + (2 x 1) = 384 + 24 + 2 = (410)10 Conversion of decimal to octal (base 10 to base 8) Example: convert (177)10 to octal 177 8 = 22 remainder is 1 22 8 = 2 remainder is 6 2 8 = 0 remainder is 2 Note: the answer is read from bottom to top as (261)8, the same as with the binary case. Hexadecimal Base or radix 16 number system 1 hex digit is equivalent to 4 bits. Numbers are 0-9, A, B, C, D, E, and F. (A)16 = (10)10, (B)16 = (11)10, (C)16 = (12)10, (D)16 = (13)10, (E)16 = (14)10, (F)16 = (15)10 Numbers are expressed as powers of 16. 160 = 1, 161 = 16, 162 = 256, 163 = 4096, 164 = 65536, … Conversion of hexadecimal to decimal ( base 16 to base 10) Example: convert (F4C)16 to decimal = (F x 162) + (4 x 161) + (C x 160) = (15 x 256) + (4 x 16) + (12 x 1) = 3840 + 64 + 12 = (3916)10 Conversion of decimal to hex (base 10 to base 16) Example: convert (77)10 to hex 77 16 = 4 remainder is D 4 16 = 0 remainder is 4 Note: the answer is read from bottom to top as (4D)16, the same as with the binary case. Number Systems - 2 decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F binary decimal 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 hexadecimal 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F binary 00010000 00010001 00010010 00010011 00010100 00010101 00010110 00010111 00011000 00011001 00011010 00011011 00011100 00011101 00011110 00011111 Table 1: Decimal, hexadecimal and binary numbers Conversion of Octal and Hex to Binary Conversion of octal and hex numbers to binary is based upon the the bit patterns shown in the table above and is straight forward. For octal numbers, only three bits are required. Thus 68 = 1102, and 3458 = 111001012. For hex numbers, four bits are required. Thus E16 = 11102, and 47D16 = 100011111012. Conversion of Binary to Octal and Hex Conversion of binary numbers to octal and hex simply requires grouping bits in the binary numbers into groups of three bits for conversion to octal and into groups of four bits for conversion to hex. Groups are formed beginning with the LSB and progressing to the MSB. Thus, 111001112 = 3478 and 111000101010100100012 = 70252218. Similarly, 111001112 = E716 and 110001010100001112 = 18A8716. Number Systems - 3 DECIMAL NUMBER SYSTEM Decimal system is a BASE TEN system It uses 10 symbols: 0,1,2,3,4,5,6,7,8,9 Expand the decimal number 6,458 6,458 = ( 6 x 103 )+ ( 4 x 102 )+ ( 5 x 101 )+ ( 8 x 100 ) Decimal place values 105 104 100,000 10,000 Hundred Ten Thousands Thousands Series of additions 103 1,000 102 100 101 10 100 1 Thousands Hundreds Tens Ones BINARY NUMBER SYSTEM Binary number system is said to be a Base Two Number of symbols—2 Symbols “0” and “1” A bit in the binary system is like a digit in the decimal system 211 210 2048 1024 29 512 28 256 27 128 26 64 25 32 24 16 23 8 22 4 21 2 20 1 CONVERT BINARY TO DECIMAL --- Series of additions 11002 = ( 1 x 23 )+ ( 1 x 22 )+ ( 0 x 21 )+ ( 0 x 20 ) = 8 + 4 + 0 + 0 = 1210 100012 = (1 x 24) + ( 0 x 23 )+ ( 0 x 22 )+ ( 0 x 21 )+ ( 1 x 20 ) = 16 + 0 + 0 + 0 + 1 = 1710 1010112= (1 x 25) + (0 x 24) + ( 1 x 23 )+ ( 0 x 22 )+ ( 1 x 21 )+ ( 1 x 20 ) = 32 + 0 + 8 + 0 + 2 + 1 = 4310 1111012= (1 x 25) + (1 x 24) + ( 1 x 23 )+ ( 1 x 22 )+ ( 0 x 21 )+ ( 1 x 20 ) = 32 + 16 + 8 + 4 + 0 + 1 = 6110 1102 = 610 Number Systems - 4 10102 = 1010 1100002 = 4810 111112 = 3110 CONVERT DECIMAL TO BINARY --- Series of subtractions 211 2048 210 1024 29 512 28 256 27 128 26 64 25 32 24 16 23 8 710 = 3410 = 22 4 1 21 2 1 20 1 1 = 1112 1 0 0 0 1 0 = 1000102 1 0 1 1 0 0 1 = 10110012 1 0 0 1 0 1 1 = 110010112 1910 = 1 0 0 1 1 = 100112 2210 = 1 0 1 1 0 = 101102 1 1 1 1 = 11112 8910 = 20310 = 1 1510 = 3610 = 1 0 0 1 0 0 = 1001002 4810 = 1 1 0 0 0 0 = 1100002 3910 = 1 0 0 1 1 1 = 1001112 6410 = 1 0 0 0 0 0 0 = 10000002 10310 = 1 1 0 0 1 1 1 = 11001112 EXAMPLE: 710 = 1112 because 7- 4 = 3 3–2=1 1 - 1= 0 HEXADECIMAL NUMBER SYSTEM Hexadecimal number system is a Base Sixteen Number Systems - 5 Number of symbols—16 Symbols 0,1,2,3,4,5,6,7,8,9, A, B, C, D, E, F 10, 11, 12, 13, 14, 15 1611 1610 169 168 167 166 165 164 163 16,777,216 1,048,576 65,536 4,096 162 256 161 16 160 1 CONVERT HEXADECIMAL TO DECIMAL --- Series of additions 7216 = ( 7 x 161 )+ ( 2 x 160 ) = 112 + 2 = 11410 235916 = ( 2 x 163 )+ ( 3 x 162 )+ ( 5 x 161 )+ ( 9 x 160 ) = 8192 + 768 + 80 + 9 = 904910 C2916 = ( C x 162 )+ ( 2 x 161 )+ ( 9 x 160 ) = 3072 + 32 + 9 = 311310 12AB16 = ( 1 x 163 )+ ( 2 x 162 )+ ( 10 x 161 )+ ( 11 x 160 ) = 4096 + 512 + 160 + 11 = 477910 3AC216 = ( 3 x 163 )+ ( 10 x 162 )+ ( 12 x 161 )+ ( 2 x 160 ) = 12288 + 2560 + 192 + 2 = 1504210 Number Systems - 6 CONVERT DECIMAL TO HEXADECIMAL --- Series of subtractions Allowable symbols 0, 1, 2, 3, 4,5, 6, 7, 8, 9, A, B, C, D, E, F 10, 11, 12, 13, 14, 15 166 16,777,216 165 1,048,576 164 65,536 163 4096 67210 = 162 256 2 161 16 A 160 1 0 = 2A016 1,76310 = 6 E 3 = 6E316 1,32410 = 5 2 C = 52C16 A B C D = ABCD16 2 A B = F2A3B16 3 1 8 = 31D816 43,98110 = 993,85110 = F 12,76010 = 3 D For example: 2 @ 256 10 @ 16 672 -512 160 -160 0 2A016 5 @ 256 2 @ 16 1763 6 @ 256 -1536 227 14 @ 16 -224 3 6E316 1324 -1280 44 - 32 12 52C16 10 @ 4096 11 @ 256 12 @ 16 43,981 - 40,960 3021 - 2816 205 -192 13 ABCD16 Number Systems - 7 Binary to Hexadecimal 1010 1100b 10 1110 1001 b 12 A 14 C 9 6 9 6 E ACh 0011 1111b 0110 1011 b 11 6Bh 0001 1000b 0101 1010b 12 4 C 4Ch 3 15 1 8 5 10 3 F 1 8 5 A 18h 1100 4 B E9h 3Fh 0100 1101 0111 13 D 5Ah 7 7 D7h Hexadecimal to Binary 83h 57h 21h 1000 0011b 0101 0111b 0010 0001b 3Ch 0011 1100b 4Fh 0100 1111b DBh 1101 1011b ABh 1010 1011b EEh 1110 1110b Number Systems - 8