Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
Number Systems and Codes 1 NUMBER SYSTEMS AND CODES Topics to be covered: Number systems Number notations Arithmetic Base conversions Signed number representation Codes Decimal codes Error detection code Gray code ASCII code 1. Number Systems The decimal (real), binary, octal hexadecimal number systems are used to represent information in digital systems. Any number system consists of a set of digits and a set of operators (+, , , ). The radix or base of the number system denotes the number of digits used in the system. Decimal (base 10) Binary (base 2) Octal (base 8) 0 1 2 3 4 5 6 7 8 9 0 1 0 1 2 3 4 5 6 7 Hexadecimal (base 16) 0 1 2 3 4 5 6 7 8 9 A B C D E F Decimal Binary Octal Hexadecimal 00 0000 00 0 01 0001 01 1 02 0010 02 2 03 0011 03 3 04 0100 04 4 05 0101 05 5 06 0110 06 6 07 0111 07 7 08 1000 10 8 09 1001 11 9 10 1010 12 A 11 1011 13 B Number Systems and Codes 12 1100 14 C 13 1101 15 D 14 1110 16 E 15 1111 17 F 2 1.1 Number notations A number can be represented in either positional notation or polynomial notation. Positional notation It is convenient to represent a number using positional notation. A positional notation is written as a sequence of digits with a radix point separating the integer and fractional part. N r an1an2 a1a0 . a1a2 am r where r is the radix, n is the number of digits of the integer part, and m is the number digits of the fractional part. Polynomial notation A number can be explicitly represented in polynomial notation. N r a n 1 r n 1 a n 2 r n 2 a1 r 1 a0 r 0 a 1 r 1 a 2 r 2 a m r m where rp is a weighted position and p is the position of a digit. In decimal number system 7326.5910 7 10 3 3 10 2 2 101 6 10 0 5 10 1 9 10 2 In binary number system 11010.0112 1 2 4 1 2 3 0 2 2 1 21 0 2 0 0 2 1 1 2 2 1 2 3 In octal number system 673.1248 6 8 2 7 81 3 80 1 8 1 2 8 2 4 8 3 In hexadecimal number system 306.D 16 3 16 2 0 161 6 16 0 D 2 1 Number Systems and Codes 1.2 Arithmetic Addition In binary number system, (101101)2 +(11101)2 : 1111 1 101101 + 11101 1001010 In octal system, (6254)8 +(5173)8 : 1 1 6254 + 5173 13447 In hexadecimal system, (9F1B)16 +(4A36)16 : + 1 1 9F1B 4A36 D951 Subtraction In binary number system, (101101)2 -(11011)2 : - 10 10 101101 11011 10010 In octal system, (6254)8 -(5173)8 : - 8 6254 5173 1061 In hexadecimal system, (9F1B)16 -(4A36)16 : - Multiplication In binary number system, 16 9F1B 4A36 54E5 3 Number Systems and Codes (1101)2 (1001)2 : 1101 1001 1101 0000 0000 1101 1110101 Division In binary number system, 1101 (1110111)2 (1001)2 : 1001 1110111 1001 1011 1001 1011 1001 10 1.3 Base conversions Convert (100111010)2 to base 8 1001110102 or 1 2 8 0 2 7 0 2 6 1 2 5 1 2 4 1 2 3 0 2 2 1 21 0 2 0 4 8 2 4 81 2 81 1 81 2 8 0 4 8 2 7 81 2 8 0 4728 1001110102 100 4 111 0102 7 2 4728 Convert (100111010)2 to base 10 1001110102 1 2 8 0 2 7 0 2 6 1 2 5 1 2 4 1 2 3 0 2 2 1 21 0 2 0 25610 32 10 1610 810 210 314 10 Convert (100111010)2 to base 16 1001110102 1 2 8 0 2 7 0 2 6 1 2 5 1 2 4 1 2 3 0 2 2 1 21 0 2 0 1 16 2 2 161 1 161 8 16 0 2 16 0 1 16 2 3 161 A 16 0 13 A16 4 Number Systems and Codes or 1001110102 0001 1 0011 10102 3 A 13 A16 Convert (372)8 to base 2 3728 3 7 2 011 111 010 111110102 Convert (372)8 to base 10 3728 3 8 2 7 81 2 8 0 19210 5610 2 10 25010 Convert (372)8 to base 16 3728 1111 F 10102 A FA16 Convert (9F2)16 to base 2 9F 216 9 F 2 1001 1111 0010 1001111100102 Convert (9F2)16 to base 8 9 F 216 9 F 2 1001 1111 0010 (100 111 110 010) 2 47628 4 7 6 2 Convert (9F2)16 to base 10 9 F 216 9 16 2 F 161 2 16 0 230410 24010 210 254610 Binomial expansion (series substitution) To convert a number in base r to base p. 1) Represent the number in base p in binomial series. 2) Change the radix or base of each term to base p. 3) Simplify. 5 Number Systems and Codes 6 Convert base 10 to base r Convert (174)10 to base 8 8 1 7 8 2 8 4 1 2 0 6 5 2 LSB MSB Therefore (174)10 = (256)8 Convert (0.275)10 to base 8 8 8 8 8 8 0.275 0.200 0.600 0.800 0.400 2.200 1.600 4.800 6.400 3.200 1. 3695 0.7390 1.4780 0.9560 1.9120 MSD LSD Therefore (0.275)10 = (0.21463)8 Convert (0.68475)10 to base 2 2 2 2 2 2 0.68475 0.3695 0.7390 0.4780 0.9560 MSD LSD Therefore (0.68475)10 = (0.10101)2 1.4 Signed Number Representation There are 3 systems to represent signed numbers: Signed-magnitude 1's complement 2's complement In binary number system Signed-magnitude system In signed-magnitude systems, the most significant bit represents the number's sign, while the remaining bits represent its absolute value as an unsigned binary magnitude. If the sign bit is a 0, the number is positive. If the sign bit is a 1, the number is negative. Number Systems and Codes 7 1's Complement system A 1's complement system represents the positive numbers the same way as in the signed-magnitude system. The only difference is negative number representations. __ Let be N any positive integer number and N be a negative 1's complement integer of N. If the number legnth is n bits, then N (2 n 1) N . For example in a 4-bit system, 0101 represents +5 and 2 4 0001 0101 (10000 0001) 0101 1111 0101 1010 1010 represents 5 Number Systems and Codes 8 2's Complement System A 2's complement system is similar to 1's complement system, except that there is only one representation for zero. __ Let be N any positive integer number and N be a negative 2's complement integer of N. If the length of the number is n bits, then N 2n N. For example in a 4-bit system, 0101 represents +5 and 2 4 0101 10000 0101 1011 1011 represents 5 Adding and subtracting signed numbers Signed-magnitude system (a) 5 +2 7 0101 +0010 0111 (b) -5 -2 -7 1101 +1010 1111 (c) 5 -2 3 0101 +1010 0011 (d) -5 +2 -3 1101 +0010 1011 Number Systems and Codes 1's complement system 5 +2 7 (a) 0101 +0010 0111 (b) -5 -2 -7 1010 +1101 1 0111 1 1000 (c) 5 -2 3 0101 +1101 1 0010 1 0011 (d) -5 +2 -3 1010 +0010 1100 2's complement system 5 +2 7 (a) 0101 +0010 0111 (b) -5 -2 -7 1011 +1110 1 1001 (c) 5 -2 3 0101 +1110 1 0011 (d) -5 +2 -3 1011 +0010 1101 Overflow conditions Carry-in carry-out 5 +3 -8 0111 0101 +0011 1000 9 Number Systems and Codes -5 -4 7 1000 1011 +1100 1 0111 5 +2 7 0000 0101 +0010 0111 -6 -2 -8 1110 1010 +1110 1 1000 Carry-in = carry-out 2. Codes 2.1. Decimal codes Decimal Digit 0 1 2 3 4 5 6 7 8 9 BCD 8421 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 Excess-3 2421 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 0000 0001 0010 0011 0100 1011 1100 1101 1110 1111 2.2. Error detection code Parity bit Odd Parity P Message 1 0000 0 0001 0 0010 1 0011 0 0100 1 0101 1 0110 Even Parity P Message 0 0000 1 0001 1 0010 0 0011 1 0100 0 0101 0 0110 10 Number Systems and Codes 0 0 1 1 0 1 0 0 1 0111 1000 1001 1010 1011 1100 1101 1110 1111 1 1 0 0 1 0 1 1 0 0111 1000 1001 1010 1011 1100 1101 1110 1111 2.3. Gray code Decimal Equivalent 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 2.4. ASCII code Binary Code 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Gray Code 0000 0001 0011 0010 0110 0111 0101 0100 1100 1101 1111 1110 1010 1011 1001 1000 11