DIGITAL CIRCUIT DESIGN EEE122 A Ref. Morris MANO & Michael D. CILETTI DIGITAL DESIGN 4th edition Fatih University- Faculty of Engineering- Electric and Electronic Dept. Signed Numbers Digital systems, such as computer, must be able to handle both positive and negative numbers. A signed binary number consists of both sign and magnitude information. • The sign indicates whether a number is positive or negative. • The magnitude is the value of the number. Signed Numbers There are 3 forms in which signed integer numbers can be represented in binary: • Sign-magnitude (least used) • 1’s complement • 2’s complement (most used) The left-most bit in a signed binary number is the sign bit. It tells whether the number is positive (sign bit = 0) or negative (sign bit = 1). Sign-Magnitude Form The left-most bit is the sign bit and the remaining bits are the magnitude bits. • The magnitude bits are in true binary for both positive and negative numbers. ex: the decimal number +25 is expressed as an 8-bit signed binary number as: 00011001 While the decimal number -25 is expressed as 10011001 “ In the sign-magnitude form, a negative number has the same magnitude bits as the corresponding positive number but the sign bit is a 1 rather than a 0. “ 1’s Complement Form Positive numbers in 1’s complement form are represented the same way as the positive sign-magnitude. Negative numbers are the 1’s complements of the corresponding positive numbers. ex: the decimal number +25 is expressed as: 00011001 While the decimal number -25 is expressed as 11100110 2’s Complement Form Positive numbers in 2’s complement form are represented the same way as the positive sign-magnitude and 1’s complement form. Negative numbers are the 2’s complements of the corresponding positive numbers. ex: the decimal number +25 is expressed as: 00011001 While the decimal number -25 is expressed as 11100111 Decimal Value of Signed Numbers Sign-magnitude: Both positive and negative numbers are determined by finding the equivalent decimal to the binary number excluding the sign bit. The sign bit will determine the final sign. Sign-magnitude ex: decimal values of these numbers (expressed in sign-magnitude) 1) 10010101 2) 01110111 magnitude magnitude 26 25 24 23 22 21 20 0 0 1 0 1 0 1 = 16+4+1 = 21 sign = 1 negative Hence: 10010101 = -21 26 25 24 23 22 21 20 1 1 1 0 1 1 1 = 64+32+16+4+2+1 = 119 sign = 0 positive Hence: 01110111 = 119 Decimal Value of Signed Numbers 1’s complement: • Positive – determined by summing the weights in all bit positions where there are 1s and ignoring those positions where there are 0s. • Negative – determined by assigning a negative value to the weight of the sign bit, summing all the weights where there are 1’s, and adding 1 to the result. Decimal Value of Signed Numbers 1’s complement (by example) ex: decimal values of these numbers (expressed in 1’s complement) 1) 00010111 2) 11101000 -27 26 25 24 23 22 21 20 0 0 0 1 0 1 1 1 = 16+4+2+1 = +23 -27 26 25 24 23 22 21 20 1 1 1 0 1 0 0 0 = (-128)+64+32+8 = -24 +1 Hence: 00010111 = +23 Hence: 11101000 = -23 Decimal Value of Signed Numbers 2’s complement: • Positive – determined by summing the weights in all bit positions where there are 1s and ignoring those positions where there are 0s. • Negative – the weight of the sign bit in a negative number is given a negative value. Decimal Value of Signed Numbers 2’s complement (by example) ex: decimal values of these numbers (expressed in 2’s complement) 1) 01010110 2) 10101010 1) 01010110 2) 10101010 -27 26 25 24 23 22 21 20 0 1 0 1 0 1 1 0 -27 26 25 24 23 22 21 20 1 0 1 0 1 0 1 0 = 64+16+4+2 = +86 Hence: 01010110 = +86 = (-128)+32+8+2 = -86 Hence: 10101010 = -86 Range of Signed Integer Numbers The magnitude range of a binary number depends on the number of bits (n). Total combinations = 2n • 8 bits = 256 different numbers • 16 bits = 65,536 different numbers • 32 bits = 4,294,967,296 different numbers For 2’s complement signed numbers: • Range = -(2n-1) to +(2n-1-1) • where there is one sign bit and n-1 magnitude ex: Negative Boundary Positive Boundary 4 bits -(23) = -8 (23-1) = +7 8 bits -(27) = -128 (27-1) = +127 16 bits -(215) = -32,768 (215-1) = +32767 Arithmetic Operations with Signed Numbers Because the 2’s complement form for representing signed numbers is the most widely used in computer systems. We’ll limit to 2’s complement arithmetic on: • Addition • Subtraction Multiplication (same as multiple addition) Division (same as continuous subtraction) Addition 4 cases may occur when 2 signed numbers are added: • Both numbers positive • Positive number with magnitude larger than negative number • Negative number with magnitude larger than positive number • Both numbers negative Addition Both numbers positive: ex: 00000111 +00000100 00001011 7 +4 11 The sum is positive and is therefore in true (un complemented) binary. Positive number with magnitude larger than negative number: ex: 00001111 15 +11111010 + -6 Discard carry 1 00001001 9 The final carry bit is discarded. The sum is positive and is therefore in true (un complemented) binary. Addition Both numbers negative: ex: 11111011 +11110111 Discard 1 11110010 carry -5 + -9 -14 The final carry bit is discarded. The sum is negative and therefore in 2’s complement form. Negative number with magnitude larger than positive number: ex: 00010000 16 +11101000 + -24 11111000 -8 The sum is negative and therefore in 2’s complement form. Addition Overflow condition: • When two numbers are added and the number of bits required to represent the sum exceeds the number of bits in the two numbers, an overflow results as indicated by an incorrect sign bit. • An overflow can occur only when both numbers are + or -. ex: 01111101 +00111010 10110111 Magnitude incorrect Sign incorrect 125 + 58 183 Addition Numbers are added two at a time: • Computer add strings of numbers two numbers at a time. ex: add the signed numbers: 01000100, 00011011, 00001110, and 00010010 68 01000100 + 27 + 00011011 Add 1st two numbers 95 01011111 1st sum + 14 + 00001110 Add 3rd number 109 01101101 2nd sum + 18 + 00010010 Add 4th number 127 01111111 Final sum Subtraction Subtraction is a special case of addition. • Subtraction is addition with the sign of the subtrahend changed. • The result of a subtraction is called the difference. The sign of a positive or negative binary is changed by taking it’s 2’s complement. Subtraction Since subtraction is simply an addition with the sign of the subtrahend changed, the process is stated as follows: • To subtract two signed numbers, take the 2’s complement of the subtrahend and add. Discard any final carry. Subtraction ex: Perform each of the following subtraction of the signed numbers: (a) 00001000 – 00000011 (c) 11100111 – 00010011 (b) 00001100 – 11110111 (d) 10001000 - 11100010 (a) 00001000 +11111101 100000101 + (b) 00001100 +00001001 + 00010101 (c) 11100111 +11101101 111010100 -25 + -19 -44 8 -3 5 12 9 21 (d) 10001000 -120 +00011110 + 30 10100110 -90 The Digital Codes Binary Coded Decimal (BCD) BCD is a numerical code that normally used as interface between user and computer system to simplify data handling. The 8421 code is a well known type of BCD to deal with the situation. Thus BCD code advantages include providing an excellent interface to : • Keypad inputs • Digital readouts Binary Coded Decimal Decimal Digit 0 1 2 3 4 5 6 7 8 9 BCD 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 Note: 1010, 1011, 1100, 1101, 1110, and 1111 are not used in BCD DEC-to-BCD (a) 35 00110101 (b) 170 000101110000 BCD-to-DEC (a)10000110 (86) (b)1001010001110000 (9470) BCD Addition BCD is a decimal number coded in binary. In arithmetic operations, it behave as normal decimal numbers with some correction rules. The steps below show how to add two BCD numbers: • Add the two BCD numbers, using the rules for basic binary addition. • If a 4-bit sum is equal to or less than 9, it is a valid BCD number. • If a 4-bit sum > 9, or if a carry out of the 4-bit group is generated it is an invalid result. Add 6 (0110) to the 4-bit sum in order to correct result and return the code to 8421. If a carry results when 6 is added, simply add the carry to the next 4-bit group. BCD Addition Example:carry out the following BCD addition (a) 0101 5 +0010 +2 0111 7 (c) 1000 8 +1001 +9 Binary sum 10001 17 Add 6 + 0110 BCD sum 10111 (b)00100011 23 + 00010101 +15 00111000 38 1 (d) 000110000100 +010101110110 011100001010 01100110 011101101000 184 +576 760 The Gray Code The Gray code is unweighted and is not an arithmetic code. • There are no specific weights assigned to the bit positions. Important: the Gray code exhibits only a single bit change from one code word to the next in sequence. • This property is important in many applications, such as shaft position encoders. The Gray Code Decimal Binary Gray Code 0 1 2 3 4 5 6 7 0000 0001 0010 0011 0100 0101 0110 0111 0000 0001 0011 0010 0110 0111 0101 0100 Decimal Binary Gray Code 8 1000 1100 9 1001 1101 10 1010 1111 11 1011 1110 12 1100 1010 13 1101 1011 14 1110 1001 15 1111 1000 The Gray Code Binary-to-Gray code conversion • The MSB in the Gray code is the same as corresponding MSB in the binary number. • Going from left to right, add each adjacent pair of binary code bits to get the next Gray code bit. Discard carries. ex: convert 101102 to Gray code 1 + 0 + 1 + 1 + 0 binary 1 Gray 1 1 0 1 The Gray Code Gray-to-Binary Conversion • The MSB in the binary code is the same as the corresponding bit in the Gray code. • Add each binary code bit generated to the Gray code bit in the next adjacent position. Discard carries. ex: convert the Gray code word 11011 to binary 1 + 1 1 + 0 0 + 0 1 + 1 1 Gray 0 Binary ASCII ASCII has 128 characters and symbols represented by a 7-bit binary code. • It can be considered an 8-bit code with the MSB always 0. (00h-7Fh) 00h-1Fh (the first 32) – control characters 20h-7Fh – graphics symbols (can be printed or displayed) ASCII CODE Table Binary Storage and Registers A binary cell: is a device that have the ability to store two stable binary information (0 and 1), the input to the cell receives an excitation signal and set its output to either 0 or 1. Register: is a group of n digital storage elements capable of storing n bits of binary information Register Transfer: For large systems, digital circuit are designed using modular approach, so the system is partitioned into subsystems, that performs some functional task. Registers are assumed to be the basic element of the digital system, the information flow and the processing performed are through register Binary Storage and Registers Binary Storage and Registers Binary Information processing through registers Binary Logic Binary Logic deals with variables that take two discrete values and with operations that assume logical meaning. It consist of binary variables (x,y,z,...A,B,C,..) and a set of binary operations. Each variable can have only one of two possible values (True/False) or (Yes/No) or (1/0) There are three basic operations: AND, OR, and NOT. AND: z=x AND y or x.y or xy; Z is true only if both x and y are true OR: z=x OR y, x+y; Z is true if at least one of the variables is true NOT: z=NOT x, x ,x’; its a complement operation Logic Operation is not mathematic operation Truth tables are used to express all possible combination of the input variables and their corresponding output logic Logic Gates Logic gates are electronic circuits that operate on one or more input signals to produce an output signal Logic Gates Inpu/Output signal for gates: