Yuh-Jzer JoungDigital Systems1 Number Systems decimal number : 7397=7× × × ×10 0 a 4 a 3 a 2 a 1 a 0. a -1 a -2 = a 4 ×10 4 +a 3 ×10 3 +a 2 ×10 2 +a 1 ×10 1 +a 0 ×10 0 +a -1 x a -2 ×10 -2 a i : coefficient 10 : base or radix a 4 : most significant bit ( msb ) a -2 : least significant bit ( lsb )
Yuh-Jzer JoungDigital Systems2 In general, number N in a base-r system is represented as N = (a n a n a 1 a 0. a -1 a a -m ) which has the value N = (a n.r n + a n-1.r n a 1.r +a 0 +a -1.r -1 + a -2 r a -m.r -m ) In binary system ﹐ r = 2 ﹐ a i {0, 1}. In octal system ﹐ r = 8 ﹐ a i {0,1,…,7}. In decimal system ﹐ r = 10 ﹐ a i {0,1,…,9}. In hexadecimal system ﹐ r = 16 ﹐ a i {0,1,…9,A,B,C,D,E,F}.
Yuh-Jzer JoungDigital Systems3 Conversion between different Bases Base-r to base-10 conversion ﹕ Straightforward ﹗ Base-r to base-s conversion ﹕ By repeated division for integers and repeated multiplication for fractions. Ex1. Convert ( ) 10 to octal number. Integer ﹕ 153 (153) 10 = (231)
Yuh-Jzer JoungDigital Systems4 fractional: 0.513×8 = ×8 = ×8 = (0.513) 10 = (0.4065…) ×8 = ( ) 10 = ( …) 8 Ex2. Convert (12A) 16 to octal. 1. Convert (12A) 16 to (298) Convert (298) 16 to octal as in Ex1.
Yuh-Jzer JoungDigital Systems5 Conversions between binary ﹐ octal ﹐ and hexadecimal can be done in a simpler way. Ex1. Convert ( ) 2 to octal and hexadecimal (2723) (5D3) 16 5 D 3 Ex2. Convert (12A7F) 16 to binary and octal. 1 2 A 7 F binary octal
Yuh-Jzer JoungDigital Systems6 Complement ﹕ for simplifying subtraction. Two types of complements for each base-r system ﹕ (r-1)’s complement r’s complement The (r-1)’s complement of an n-digital number N ﹕ ( r n 1) N Ex. In decimal system ﹐ the 9’s complement of is (10 6 1) = = The 9’s complement of is = The 1’s complement of is (2 8 1) = = The 1’s complement of is
Yuh-Jzer JoungDigital Systems7 The r’s complement of an n-digital number N ﹕ r n N N ≠0 0 N = 0 Ex. The 10’s complement of is The 10’s complement of is The 2’s complement of is The 2’s complement of is Comments ﹕ 1.To compute the complement of a number having radix point, first ﹐ remove the radix point ﹐ compute the complement of the new number ﹐ and restore the radix point. Ex. The 1’s complement of is The 2’s complement of is
Yuh-Jzer JoungDigital Systems8 2.The complement of the complement of N is N. (r 1)’s complement of (2 n 1) N = (2 n 1) ((2 n 1) N) = N Signed Binary Numbers Addition ﹕ Subtraction ﹕ 13 1101 4 ?
Yuh-Jzer JoungDigital Systems9 How do we represent signed numbers in digital systems? representation of +9 with 8 bits: representation of 9: signed magnitude: signed -1’s-complement: signed -2’s-complement: Numbers that can be represented in n bits: signed magnitude: ( 2 n 1 +1) ~ (2 n 1 1) signed-1’s-complement: ( 2 n 1 +1) ~ (2 n 1 1) signed-2’s-complement: ( 2 n 1 ) ~ (2 n 1 1)
Yuh-Jzer JoungDigital Systems10 Addition and Subtraction on signed-magnitude numbers Summary: to perform arithmetic operations on signed magnitude numbers, we need to compare the signs and the magnitudes of the two numbers, and then perform either addition or subtraction.
Yuh-Jzer JoungDigital Systems11 Addition and subtraction on signed-2’s-complement numbers: Addition: add the corresponding digits ( including the sign digits) and ignore any carry out discarded carryout
Yuh-Jzer JoungDigital Systems the 2’s complement of (4) the 2’s complement of (22) Discussion: ( N) + (M) (2 n N) + M = 2 n (N M) Case N > M: there will be no carry out, and the result is the 2’s complement of (N M) N M: = 2 n + (M N) there will be a carry out, and the result after discarding the carry out is (M N)
Yuh-Jzer JoungDigital Systems13 overflow: negative! positive! using 8 bits, we can represent only -128 ~ +127! When add two n-bits (including the sign bit) numbers N and M, overflow occurs when: 1. N, M 0, N+M 2 n 1 1 2. N, M < 0, N+M 2 n 1 Note that overflow cannot occur if one of N and M is positive and the other is negative.
Yuh-Jzer JoungDigital Systems14 Subtraction: N M = N+ ( M) = N + (2’s complement of M) 13 ’s complement of
Yuh-Jzer JoungDigital Systems15 Addition and Subtraction on Signed-1’s-complement numbers: Assume that M, N 0, and they have n bits (including sign) Case M + N : normal binary addition Case N + M : (1’s complement of N) + M = [(2 n 1) N] + M = (2 n 1) (N M) Sub-case: N M 0: there will be no carry. Sub-case: N M 0: (2 n 1) (N M) = 2 n + (M N) 1 carry bit 0 So there will be a carry. To obtain (M N), we discard the carry and add 1 to the result.
Yuh-Jzer JoungDigital Systems16 Ex. end-around carry Case ( N) + ( M) = (N+M) : (1’s complement of N) + (1’s complement of M) = [(2 n 1) N] + [(2 n 1) M] = 2 n 1 + (2 n 1) (N+M) carry 1’s complement of (N+M) We obtain (2 n 1) (N M) by discarding the carry and adding 1 to the result. ’s complement of (22)
Yuh-Jzer JoungDigital Systems17 Overflow: Similar to the case of 2’s complement, an overflow occurs when N+M 2 n 1 1 or ( N) + ( M) 2 n 1 +1 An overflow can be detected by examining the most significant bit of the result (positive) (positive) (negative) (negative) 96 (negative) (positive) carry
Yuh-Jzer JoungDigital Systems18 Comparison of the three signed numbers systems : signed-magnitude: useful in ordinary arithmetic, awkward in computer arithmetic signed-1’s-complement: used in old computers, but is now seldom used. signed-2’s-complement: used in most computers.
Yuh-Jzer JoungDigital Systems19 Binary Codes Binary codes can be established for any set of discrete elements. Using n bits, we can represent at most 2 n distinct elements. So, to represent m distinct objects, we need at least log 2 m bits. For example, we need log 2 10 = 4 bits to represent { 0,1,…9}. MAN(1) WOMAN (0) WHITE(00) RED(01) BLUE(10) BLACK(11)
Yuh-Jzer JoungDigital Systems20 Decimal BCD Excess Bi-quinary digits (8421) ( ) Some possible binary codes are illustrated below.
Yuh-Jzer JoungDigital Systems21 Alphanumeric Codes -- ASCII (American Standard Code for Information Interchange) originally use 7 bits to code 128 characters since most digital systems handle 8-bit (byte) more efficiently, an 8 bit version ASCII has also been developed. -- EBDIC (Extended Binary-Coded Decimal Interchange Code) used in most IBM systems use 8 bits to code the same 128 character symbols as ASCII Gray Code each binary code differs from either its successor or predecessor by only one bit.
Yuh-Jzer JoungDigital Systems22 Decimal Gray Code bit Gray Code
Yuh-Jzer JoungDigital Systems23 Gray Code is often used in situations where other binary code might produce erroneous or ambiguous results during transitions from one code to another. If we use BCD code to transmit 0111 (7) and then 1000 (8), then, an erroneous intermediate code 1001 may be generated if the rightmost bit takes more time to change. The Gray code eliminates this problem since only one bit changes between two consecutive numbers. A/D Converter Transmitter Receiver
Yuh-Jzer JoungDigital Systems24 Generation of Gray Codes: an n-bits code is generated by reflecting the (n-1)-bit code
Yuh-Jzer JoungDigital Systems25 Error-Detecting Code Binary code that can detect errors during data transmission. The most common ways to achieve error-detection is by means of a parity bit. A parity bit is an extra bit included in a binary code to make the total number of 1’s transmitted either odd (odd parity) or (even parity). odd parity even parity message parity bit message parity bit Transmitter source Parity generator ERROR destination Parity detector Receiver
Yuh-Jzer JoungDigital Systems26 4-bits Adder FA x3x3 x1x1 y1y1 x0x0 y0y0 x2x2 y2y2 y3y3 S3S3 S0S0 S1S1 S2S2 c0c0 c4c4 c2c2 c1c1 c3c3 Full Adder xy cz S Digital Circuits
Yuh-Jzer JoungDigital Systems27 NameTruth TableAlgebraic Function AND F = xy OR F = x+y Inverter F = x’ Buffer F = x NAND F = (xy)’ Gate
Yuh-Jzer JoungDigital Systems28 NOR F = (x+y)’ Exclusive-OR (XOR) F = xy’+x’y = x y Exclusive-NOR (equivalence) F = xy+x’y’ = x y
Yuh-Jzer JoungDigital Systems29 Extension to multiple inputs xyzxyz x y z
Yuh-Jzer JoungDigital Systems30 In real implementation, the three-input Exclusive-OR is usually implemented by 2-input Exclusive-OR: Even a two input Exclusive-OR is usually constructed with other types of gates. x’y+y’x x y z x y = x’y+xy’
Yuh-Jzer JoungDigital Systems31 This is how a gate adds a binary 1 and 0 in the “ones” place. If you feed a 1 and a 0 to the gate, it puts out a 1, which is the correct result of adding a binary 1 and 0. Place
Yuh-Jzer JoungDigital Systems32 Place Addition with a carryover is a little more difficult, for instance, adding 1 plus 1. If you feed the gate a 1 and 1, it will put a 0 in the “ones” place and put a carryover of 1 in the “twos” place. This produces the correct result for adding 1 and 1 in binary.
Yuh-Jzer JoungDigital Systems33 c = f(x,y,z) = (3,5,6,7) s = (1,2,4,7) c: s: y y z x c = xy+yz+xz s = x’y’z+x’yz’+xy’z’+xyz y z x y
Yuh-Jzer JoungDigital Systems34 (a) S = xy’+x’y C = xy (b) S = (x+y)(x’+y’) C = xy Various Implementations of a half-adder
Yuh-Jzer JoungDigital Systems35 (c) S = (C + x’y’)’ C = xy (d) S = (x+y)(x’+y’) C = xy (e) S = x y C = xy
Yuh-Jzer JoungDigital Systems36 Binary Adder and Subtractor = x y z = xy + yz + xz 4-bit parallel adder
Yuh-Jzer JoungDigital Systems37 4-bit adder-subtractor