69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1, * *10 + 4*1 n Alternate view: Digit position I from the right = Digit * 10 I (rightmost is position 0) n 2534 = 2* * * *10 0
70 Base R Numbers n Each digit in range 0..(R-1) n 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F... n A = 10 n B = 11 n C = 12 n D = 13 n E = 14 n F = 15 n Digit position I = Digit * R I n D 3 D 2 D 1 D 0 (base R) = D 3 *R 3 +D 2 *R 2 +D 1 *R 1 +D 0 *R 0
71 Number System (Conversion to Decimal) n Binary: (101110) 2 = n Octal: (7325) 8 = n Hexadecimal: (AFE32) 16 =
72 Conversion from Base R to Decimal n Binary: (110101) 2 n Octal: (6524) 8 n Hexadecimal: (94a6) 16
73 Conversion of Decimal to Binary (Method 1) n For positive, unsigned numbers n Successively subtract the greatest power of two less than the number from the value. Put a 1 in the corresponding digit position 2 0 =1 2 4 = = =4096 (4K) 2 1 =2 2 5 = = =8192 (8K) 2 2 =4 2 6 = =1024 (1K) 2 3 =8 2 7 = =2048 (2K)
74 Decimal to Binary Method 1 n Convert (2578) 10 to binary n Convert (289) 10 to binary
75 Conversion of Decimal to Binary (Method 2) n For positive, unsigned numbers n Repeatedly divide number by 2. Remainder becomes the binary digits (right to left) n Explanation:
76 Decimal to Binary Method 2 n Convert (289) 10 to binary
77 Decimal to Binary Method 2 n Convert (85) 10 to binary
78 Converting Binary to Hexadecimal n 1 hex digit = 4 binary digits n Convert ( ) 2 to hex n Convert (A3FF2A) 16 to binary
79 Converting Binary to Octal n 1 octal digit = 3 binary digits n Convert ( ) 2 to octal n Convert (723642) 8 to binary
80 Converting Decimal to Octal/Hex n Convert to binary, then to other base n Convert (198) 10 to Hexadecimal n Convert ( ) 10 to Octal
81 Arithmetic Operations Decimal: Binary: Decimal: Binary:
82 Arithmetic Operations (cont.) * Binary:
83 Negative Numbers n Need an efficient way to represent negative numbers in binary n Both positive & negative numbers will be strings of bits n Use fixed-width formats (4-bit, 16-bit, etc.) n Must provide efficient mathematical operations n Addition & subtraction with potentially mixed signs n Negation (multiply by -1)
84 Sign/Magnitude Representation = = High order bit is sign: 0 = positive (or zero), 1 = negative Three low order bits is the magnitude: 0 (000) thru 7 (111) Number range for n bits = +/-2 -1 Representations for 0: n-1
85 Sign/Magnitude Addition ( -2) (+4) (+2) (+4) (-2) (-4) (+2) ( -4) Bottom line: Basic mathematics are too complex in Sign/Magnitude Idea: Pick negatives so that addition/subtraction works
86 Idea: Pick negatives so that addition works n Let -1 = 0 - (+1): n Does addition work? n Result: Two’s Complement Numbers ( 0) (+1) (+2) ( -1)
87 Two’s Complement n Only one representation for 0 n One more negative number than positive number n Fixed width format for both pos. & neg. numbers = =
88 Negating in Two’s Complement n Flip bits & Add 1 n Negate (0010) 2 (+2) n Negate (1110) 2 (-2)
89 Addition in Two’s Complement ( -2) (+4) (+2) (+4) (-2) (-4) (+2) ( -4)
90 Subtraction in Two’s Complement n A - B = A + (-B) = A + B + 1 n n n
91 Overflows in Two’s Complement Add two positive numbers to get a negative number or two negative numbers to get a positive number = =
92 Overflow Detection in Two’s Complement Overflow No overflow Overflow when carry in to sign does not equal carry out
93 Converting Decimal to Two’s Complement n Convert absolute value to binary, then negate if necessary n Convert (-9) 10 to 6-bit Two’s Complement n Convert (9) 10 to 6-bit Two’s Complement
94 Converting Two’s Complement to Decimal n If Positive, convert as normal; If Negative, negate then convert. n Convert (11010) 2 to Decimal n Convert (01011) 2 to Decimal
95 Sign Extension n To convert from N-bit to M-bit Two’s Complement (N>M), simply duplicate sign bit: n Convert (1011) 2 to 8-bit Two’s Complement n Convert (0010) 2 to 8-bit Two’s Complement
96 Sign Extension n To convert from N-bit to M-bit Two’s Complement (N>M), simply duplicate sign bit: n Convert (1011) 2 to 8-bit Two’s Complement n Convert (0010) 2 to 8-bit Two’s Complement
97 Half Adder With twos complement numbers, addition is sufficient Half-adder Schematic
98 Full Adder A B CI S CO
99 Full Adder/Half Adder Alternative Implementation: 5 Gates A B + CI (A xor B) = A B + B CI + A CI Standard Approach: 6 Gates + A A A B B B CI S CO
100 Multi-Bit Addition Cascaded Multi-bit Adder usually interested in adding more than two bits this motivates the need for the full adder
101 Adder/Subtractor A - B = A + (-B) = A + B + 1 AB CO S +CI AB CO S +CI AB CO S +CI AB CO S +CI A 3 B 3 A 2 B 2 A 1 B 1 A 0 B 0 S 3 S 2 S 1 S 0 Overflow