Number Systems
Number Systems
STRUCTURE 1.0 Objectives 1.1 Introduction 1.2 Number Systems 1.2.1 Binary Number System 1.2.2 Octal Number System 1.2.3 Hexadecimal Number System 1.2.4 Binary Arithmetic 1.2.5 BCD Addition 1.2.6 Alphanumeric Codes
Check Your Progress 1 1.3 Boolean Algebra and Logic Gates 1.3.1 AND Gate 1.3.2 OR Gate 1.3.3 NOT Gate 1.3.4 NAND Gate 1.3.5 NOR Gate 1.3.6 XOR Gate 1.3.7 Basic Laws of Boolean Algebra 1.3.8 De-Morgans Theorems
Check Your Progress 2 1.4 Summary 1.5 Glossary 1.6 References 1.7 Answers to Check Your Progress Questions
1.0 OBJECTIVES After going through this unit, you will be able to understand the decimal, binary, octal and hexadecimal number systems convert from one number system into another apply arithmetic operations to binary numbers understand BCD codes and alpha numeric codes learn the operations of logic gates apply the basic laws of Boolean algebra apply De Morgans theorems to Boolean expressions
1.1 INTRODUCTION
The binary number system and digital codes are fundamental to computers. In this chapter, the binary number system and its relationship to other systems such as decimal, hexadecimal, and octal are introduced. Arithmetic operations with binary numbers are discussed to provide a basis for understanding how computers and many other types of digital systems work. Also binary coded decimal (BCD), and alpha numeric codes are introduced. Binary logic gates are explained with the help of logic diagram, block diagram and truth table. Basic laws of Boolean Algebra are given. DeMorgans theorems are also stated and proved.
Each digit in a binary number has a value or weight. The LSB has a value of 1. The second from the right has a value of 2, the next 4 , etc., 16 24 8 23 4 22 2 21 1 20
Binary to decimal conversion: (1001)2 = X10 1001 =1x23 + 0x22 + 0x21 +1x20 =8+0+0+1 (1001)2 = (9)10 Fractions: For fractions the weights of the digit positions are written from right of the binary point and weights are given as follows. 2-1 E.g.: (0.0110) 2= X10 =0x2-1 + 1x2-2+ 1x2-3 + 0x2-4 =0 x0.5 + 1x0.25 + 1x0.125 + 0x0.0625 = (0.375)10 E.g.: (1011.101) 2=X10 =1x23 + 0x22 + 1x21 + 1x20 + 1x2-1 + 0x2-2 + 1x2-3 =8 + 0 + 2 + 1 + 0.5 + 0 + 0.125 = (11.625)10 Decimal to binary conversion: (Double Dabble method) In this method the decimal number is divided by 2 progressively and the remainder is written after each division. Then the remainders are taken in the reverse order to form the binary number. E.g.: (12)10 = X2 2-2 2-3 2-4 2-5
(12)10 = (1100)2
E.g.:
(21)2 = X2
(21)2 = (10101)2 Fractions: The fraction is multiplied by 2 and the carry in the integer position is written after each multiplication. Then they are written in the forward order to get the corresponding binary equivalent. E.g.: (0.4375)10 = X2 2 x 0.4375 = 0.8750 => 0 2 x 0.8750 = 1.750 => 1 2 x 0. 750 = 1.5 => 1 2 x 0.5 = 1.0 => 1 (0.4375)10 = (0.0111)2
To convert from octal to decimal multiply each octal digit by its weight and add the resulting products.
E.g.:
(48)8 = X10 48 = 4 x 81 + 7 x 80 = 32 + 7 = 39 (48)8 = (39)10 E.g.: (22.34)8 = X10 22.34 = 2 x 81 + 2 x 80 + 3 x 8-1 + 4 x 8-2 =16 + 2 + 3 x 1/8 +4 x 1/64 = (18.4375) (22.34)8 = (18.4375)10 Decimal to octal conversion: Here the number is divided by 8 progressively and each time the remainder is written and finally the remainders are written in the reverse order to form the octal number. If the number has a fraction part, that part is multiplied by 8 and carry in the integer part is taken. Finally the carries are taken in the forward order. E.g.: (19.11)10 = X8
0.11 x 8 = 0.88 => 0 0.88 x 8 = 7.04 => 7 0.04 x 8 = 0.32 => 0 0.32 x 8 = 2.56 => 2 0.56 x 8 = 4.48 => 4 (19.11)10 = (23.07024)8
Octal to binary conversion: Since the base of octal number is 8, i.e., the third power of 2, each octal number is converted into its equivalent binary digit of length three. E.g.:
(57.127)8 = (101111001010111)2 Binary to octal: The given binary number is grouped into a group of 3 bits, starting at the octal point and each group is converted into its octal equivalent. E.g.: (1101101.11101)2 = X8 001 101 101.111 010 1 5 5 . 7 2 (1101101.11101)2 = (155.72) 8
Binary to hexadecimal:
The binary number is grouped into bits of 4 from the binary point then the corresponding hexadecimal equivalent is written. E.g.: (100101110 . 11011) 2 = X16 0001 0010 1110 . 1101 1000 1 2 E . D 8 (100101110 . 11011) 2 = (12E . D8)16 Hexadecimal to binary: Since the base of hexadecimal number is 16, i.e., the fourth power of 2, each hexadecimal number is converted into its equivalent binary digit of length four. E.g.: (5D. 2A)16 = X2 5 D . 2 A 0101 1101 . 0010 1010 (5D. 2A)16 = (01011101.00101010)2 Decimal to hexadecimal: The decimal number is divided by 16 and carries are taken after each division and then written in the reverse order. The fractional part is multiplied by 16 and carry is taken in the forward order.
E.g.: (2479.859)) 10 = X 16
(2479.859)10 = (9AF.DBE76)16 Hexadecimal to decimal: Each digit of the hexadecimal number is multiplied by its weight and then added. E.g.: (81.21) 16 = X10 =8 x 161 + 1 x 160 + 2 x 16-1 + 1 x 16-2 =8 x 16 + 1 x 1 + 2/16 + 1/162 = (129.1289)10 (81.21) 16 = (129.1289)10
00=0
10=1 11=0 0 1 = 1 with a borrow of 1 is equivalent to 10 1 = 1 E.g.: 111 010 101 E.g.: 110.01 100.10 001.11 1s complement: To obtain 1s complement of a binary number each bit of the number is subtracted from 1.
E.g.: Binary number 0101 1001 1101 0001 1s Complement 1010 0110 0010 1110
Thus 1s complement of a binary number is the number that results when we change each 0 to a 1 and each 1 to a 0. 1s complement subtraction: Instead of subtracting the second number from the first, the 1s complement of the second number is added to the first number. The last carry which is said to be a END AROUND CARRY, is added to get the final result. E.g.: 73 4 111 -----------------> 111 + 011 1s complement 100 1011 + 1 100 result
If there is no carry in the 1s complement subtraction, it indicates that the result is a negative and number will be in its 1s complement form. So complement it to get the final result. E.g.: 810 4 1000 -----------------> 1000 + 1010 1s complement 0101 1101 1s complement - 0010 result
The following points should be noted down when we do 1s complement subtraction. 1. 2. 3. 4. 5. 6. Write the first number (minuend) as such. Write the 1s complement of second number(subtrahend) Add the two numbers. The carry that arises from the addition is said to be end around carry. End-around carry should be added with the sum to get the result. If there is no end around carry find out the 1s complement of the sum and put a negative sign before the result as the result is negative.
2s Complement: 2s complement results when we add 1 to 1s complement of the given number i.e., 2s complement =1s complement + 1 Binary Number 1010 0101 1001 0001 1s complement 0101 1010 0110 1110 2s complement 0110 1011 0111 1111
2s Complement Subtraction: Steps: 1. 2. 3. 4. Write the first number as such Write down the 2s complement of the second number. Add the two numbers. If there is a carry, discard it and the remaining part (sum) will be the result (positive). 5. If there is no carry, find out the 2s complement of the sum and put negative sign before the result as the result is negative.
E.g.: 1) 10 8 2 1010 -----------------> 1010 + 1000 2s complement 1000 10010 0010 result 2) 512 4 0101 -----------------> 0101 + 1100 2s complement 0100 1001 2s complement 0111 result
Binary multiplication: The table for binary multiplication is given below 0x0=0 0x1=0 1x0=0 1x1=1 E.g.: 1011 x 110 1011 x 110 0000 1011 1011 __ 1000010_ E.g.: 101.01 x 11.01 101.01 x 11.01 101 01 00000 10101 _10101__ 10001.0001
Binary division: The table for binary division is as follows. 01=0 11=1 As in the decimal system division by zero is meaning less. E.g.: 1) 1100 11 100_ 111100 11__ 0 2) 1001 10 _100.1 10 1001 10__ 0010 10 0 1.2.5 BCD Addition Binary Coded Decimal(BCD) is a way to express each of the decimal digits with a binary code. There are only ten code groups in the BCD system. The 8421 code is a type of BCD code. In BCD each decimal digit , 0 through 9 is represented by a binary code of four bits. The designation of 8421 indicates the binary weights of the four bits (23,22,21,20). The largest 4-bit code is 1001. The numbers 1010, 1011, 1100, 1101, 1110, and 1111 are called forbidden numbers. The following table represents the decimal and 8421 equivalent numbers. Decimal digit 0 BCD 0000 8421 Addition: In 8421 addition, if there is a carry or if it results in a forbidden group, then 0110(6) should be added in order to bring the result to the 8421 mode again. 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 8 9 0111 1000 1001
E.g.: 8 7 15
E.g.: 18 + 2 20 0001 1000 + 0000 0010 0001 1010 + 0000 0110 0010 0000
2. The binary number 1101 is equal to the decimal number (a) 13 (b) 49 (c) 11 (d) 3 3. The decimal 17 is equal to the binary number (a) 10010 (b) 11000 (c) 10001 (d) 01001 4. The sum of 11010 + 01111 equals (a) 101001 (b) 101010 (c) 110101 (d) 101000
5. The difference of 110 010 equals (a) 001 (b) 010 (c) 101
(d) 100
6. The 1s complement of 10111001 is (a) 01000111 (b) 01000110 (c) 11000110 (d) 10101010 7. The 2s complement of 11001000 is (a) 00110111 (b) 00110001 (c) 01001000 (d) 00111000 8. The binary number 101100111001010100001 can be written in octal as (a) 54712308 (b) 54712418(c) 26345218 (d) 231625018 9. The binary number 10001101010001101111 can be written in hexadecimal as (a)AD46716 (b) 8C46F16 (c) 8D46F16 (d) AE46F16 10. The BCD number for decimal 473 is (a) 111011010 (b) 1110111110101001 (c) 010001110011 (d) 010011110011
Figure 1.1 AND gate Boolean expression for AND gate operation is Y=A . B Truth table A 0 0 1 B 0 1 0 Y=A.B 0 0 0
1.3.2 OR gate An OR gate (Figure 1.2) produces a high output when any or the entire inputs are high. The output is low only when all the inputs are low.
Figure 1.2 OR gate The Boolean expression for an OR gate is Y=A+B Truth table: A 0 0 1 1 B 0 1 0 1 Y=A+B 0 1 1 1
1.3.3 NOT gate: A NOT gate (Figure 1.3) is also called an inverter. The circuit has one input and one output. The output is the complement of the input. If the input signal is high, the output is low and vice versa.
Figure 1.3 NOT gate The Boolean expression for NOT gate is Y= Truth table:
A 0 1
Y= 1 0
If two NOT gates are cascaded then the output will be same as the input and the circuit is called buffer circuit. 1.3.4 NAND gate A NAND (Figure 1.4) gate has two or more input signals but only one output signal. All input signals must be high to get a low output. When one AND gate is combined with a NOT gate, a NAND gate is obtained.
1.3.5 NOR gate: NOR gate (Fig. 1.5) has two or more input signals and one output signal. It consists of one OR gate followed by an inverter. A NOR gate produces a high output only when all the inputs are low.
1.3.6 XOR gate XOR (Figure 1.6) gate is an abbreviation of exclusive OR gate. It has two inputs and one output. For a two input XOR gate, the output is high when the inputs are different and the output is low when the inputs are same. In general, the output of an XOR gate is high when the number of its high inputs is odd. The Boolean expression of the XOR gate is _ _ Y = A.B + A.B
a) Logic diagram
Truth table: A 0 0 1 1 B 0 1 0 1 Y= A 0 1 1 0 B
Figure 1.7 Binary to Gray Converter The Figure 1.7 shows the way to convert binary number to gray number using XOR gates. Since mod-2 addition is involved in the conversion, XOR gate is used for this purpose. 2. Gray to Binary Converter: XOR gate is also used to convert gray code to a binary number. The circuit diagram for this operation is shown in the Figure 1.8.
3. Parity checker: Parity checker can be designed using XOR gates as given in the Figure 1.9. Here the parity of the word ABCD is checked. The circuit adds the bits of ABCD. A final sum of 0 implies even parity and a sum of 1 means odd parity.
6. A .1 = A 7. A .A = A 8. A . = 0 = 9. A = A 10. A + A.B =A 11. A.(A + B) = A 12. (A + B).(A+C) = A + B.C 13. A + .B =A + B 14. A.( +B) = A.B 15. (A + B).( + C) = A.C + .B 16. (A + C).( + B) = A.B + .C
_____ _____ _ L.H.S => A + B = 0 + 1 = 1 = 0 _ _ _ _ R.H.S => A . B = 0 . 1 = 1 .0 = 0 Case 3: A=1, B=0 _____ _____ _ L.H.S => A + B = 1 + 0 = 1 = 0 _ _ _ _ R.H.S => A . B = 1 . 0 = 0 .1 = 0 Case 4: A=1, B=1 _____ _____ _ L.H.S => A + B = 1 + 1 = 1 = 0 _ _ _ _ R.H.S => A . B = 1 . 1 = 0 .0 = 0 Truth table A 0 0 1 1 B 0 1 0 1 ____ _ A+B 1 0 0 0 _ _ A.B 1 0 0 0
Case 1: A=0, B=0 ____ ___ _ L.H.S => A . B = 0 . 0 = 0 = 1 _ _ _ _ R.H.S => A + B = 0 + 0 = 1 + 1 = 1 Case 2: A=0, B=1 ____ ____ _ L.H.S => A . B = 0 . 1 = 0 = 1 _ _ _ _
R.H.S => A + B = 0 + 1 = 1 + 0 = 1 Case 3: A=1, B=0 ____ ____ _ L.H.S => A . B = 1 . 0 = 0 = 1 _ _ _ _ R.H.S => A + B = 1 + 0 = 0 +1 = 1 Case 4: A=1, B=1 ____ ____ _ L.H.S => A . B = 1 . 1 = 1 = 0 _ _ _ _ R.H.S => A + B = 1 + 1 = 0 +0 = 0 Truth table A 0 0 1 1 B 0 1 0 1 ____ _ A.B 1 1 1 0 _ _ A+B 1 1 1 0
(a)NAND (b) AND (c) NOR (d) None of the above 7.The complement of a variable is always (a) 0 (b) 1 (c) equal to the variable (d) the inverse of the variable 8.Which one of the following is not a valid rule of Boolean algebra? (a) A + 1 = 1 (b) A = (c) A.A = A (d) A + 0 = A 9. Which of the following rules states that if one input of an AND gate is always 1 , the output is equal to the other input ? (a) A + 1 = 1 (b) A + A = A (c) A.A = A (d) A . 1 = A
1.4 SUMMARY
A binary number is a weighted number in which the weight of each whole number digit is a positive power of 2 and the weight of each fractional digit is a negative power of 2. The 1s complement of a binary number is derived by changing 1s to 0s and 0s to 1s The 2s complement of a binary number can be derived by adding 1 to the 1s complement. The octal number system consists of eight digits, 0 through 7. The hexadecimal number system consists of 16 digits and characters, 0 through 9 followed by A through F. The ASCII is a 7-bit alphanumeric code that is widely used in computer systems for input/output of information. The output of an inverter is the complement of its input The output of an AND gate is high only if all the inputs are high The output of an OR gate is high if any of the inputs is high The output of an NOR gate is low if any of the inputs is high The output of an NAND gate is low only if all the inputs are high The output of an exclusive-OR gate is high when the inputs are not the same
1.5 GLOSSARY
Alphanumeric : Consisting of numerals, letters, and other characters. ASCII : American Standard Code for Information Interchange.
BCD : Binary Coded Decimal ; a digit code in which each of the decimal digits , 0 through 9, is represented by a group of four bits. Binary : Describes a number system that has a base of two and utilizes 1 and 0 as its digits. Boolean algebra : The mathematics of logic circuits.
Gate : A logic circuit that performs a specified logic operation , such as AND, OR or NOT. Hexadecimal : Describes a number system with a base of 16 Octal : Describes a number system with a base of 8. Parity : Parity is based on the number of 1s in a binary word. If the number of 1s in a word is odd, then it is a odd parity word and if the number of 1s is even, then it is an even parity word. Truth table : A table showing the inputs and corresponding output levels of a logic circuit. Universal gate : Either a NAND gate or a NOR gate.
1.6 REFERENCES
1. Moris Mano, Digital Computer Fundamentals TMH 3rd Edition 2. Thomas C Bartee Computer Architecture and Logic and logic Design TMH 3. Malvino and Leech Digital Principles and Applications, TMH 4. Thomas L.Floyd Digital fundamentals Pearson Education 8th Edition
Check Your Progress 2 1.(d) 2.(d) 3.(c) 4.(b) 5.(d) 6.(b) 7.(d) 8.(b) 9.(d)