Presentation is loading. Please wait.

Presentation is loading. Please wait.

69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

Similar presentations


Presentation on theme: "69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position."— Presentation transcript:

1 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position I from the right = Digit * 10 I (rightmost is position 0) n 2534 = 2*10 3 + 5*10 2 + 3*10 1 + 4*10 0

2 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

3 71 Number System (Conversion to Decimal) n Binary: (101110) 2 = n Octal: (7325) 8 = n Hexadecimal: (AFE32) 16 =

4 72 Conversion from Base R to Decimal n Binary: (110101) 2 n Octal: (6524) 8 n Hexadecimal: (94a6) 16

5 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 =16 2 8 =256 2 12 =4096 (4K) 2 1 =2 2 5 =32 2 9 =512 2 13 =8192 (8K) 2 2 =4 2 6 =64 2 10 =1024 (1K) 2 3 =8 2 7 =128 2 11 =2048 (2K)

6 74 Decimal to Binary Method 1 n Convert (2578) 10 to binary n Convert (289) 10 to binary

7 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:

8 76 Decimal to Binary Method 2 n Convert (289) 10 to binary

9 77 Decimal to Binary Method 2 n Convert (85) 10 to binary

10 78 Converting Binary to Hexadecimal n 1 hex digit = 4 binary digits n Convert (11100011010111010011) 2 to hex n Convert (A3FF2A) 16 to binary

11 79 Converting Binary to Octal n 1 octal digit = 3 binary digits n Convert (10100101001101010011) 2 to octal n Convert (723642) 8 to binary

12 80 Converting Decimal to Octal/Hex n Convert to binary, then to other base n Convert (198) 10 to Hexadecimal n Convert (1983020) 10 to Octal

13 81 Arithmetic Operations 5 7 8 9 2 + 7 8 9 5 6 Decimal: 1 0 1 0 1 1 1 + 0 1 0 0 1 0 1 Binary: 5 7 8 9 2 - 3 2 9 4 6 Decimal: 1 0 1 0 0 1 1 0 - 0 0 1 1 0 1 1 1 Binary:

14 82 Arithmetic Operations (cont.) 1 0 0 1 * 1 0 1 1 Binary:

15 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)

16 84 Sign/Magnitude Representation 0000 0111 0011 1011 1111 1110 1101 1100 1010 1001 1000 0110 0101 0100 0010 0001 +0 +1 +2 +3 +4 +5 +6 +7 -0 -2 -3 -4 -5 -6 -7 0 100 = + 4 1 100 = - 4 + - 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

17 85 Sign/Magnitude Addition 1 0 1 0 ( -2) + 0 1 0 0 (+4) 0 0 1 0 (+2) + 0 1 0 0 (+4) 1 0 1 0 (-2) + 1 1 0 0 (-4) 0 0 1 0 (+2) + 1 1 0 0 ( -4) Bottom line: Basic mathematics are too complex in Sign/Magnitude Idea: Pick negatives so that addition/subtraction works

18 86 Idea: Pick negatives so that addition works n Let -1 = 0 - (+1): n Does addition work? n Result: Two’s Complement Numbers 0 0 0 0 ( 0) - 0 0 0 1 (+1) 0 0 1 0 (+2) + 1 1 1 1 ( -1)

19 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 0000 0111 0011 1011 1111 1110 1101 1100 1010 1001 1000 0110 0101 0100 0010 0001 +0 +1 +2 +3 +4 +5 +6 +7 -8 -7 -6 -5 -4 -3 -2 0 011 = + 3 1 101 = - 3 + -

20 88 Negating in Two’s Complement n Flip bits & Add 1 n Negate (0010) 2 (+2) n Negate (1110) 2 (-2) 0000 0111 0011 1011 1111 1110 1101 1100 1010 1001 1000 0110 0101 0100 0010 0001 +0 +1 +2 +3 +4 +5 +6 +7 -8 -7 -6 -5 -4 -3 -2

21 89 Addition in Two’s Complement 1 1 1 0 ( -2) + 0 1 0 0 (+4) 0 0 1 0 (+2) + 0 1 0 0 (+4) 1 1 1 0 (-2) + 1 1 0 0 (-4) 0 0 1 0 (+2) + 1 1 0 0 ( -4)

22 90 Subtraction in Two’s Complement n A - B = A + (-B) = A + B + 1 n 0010 - 0110 n 1011 - 1001 n 1011 - 0001

23 91 Overflows in Two’s Complement Add two positive numbers to get a negative number or two negative numbers to get a positive number 5 + 3 = -9 -7 - 2 = +7 0000 0001 0010 0011 1000 0101 0110 0100 1001 1010 1011 1100 1101 0111 1110 1111 +0 +1 +2 +3 +4 +5 +6 +7 -8 -7 -6 -5 -4 -3 -2 0000 0001 0010 0011 1000 0101 0110 0100 1001 1010 1011 1100 1101 0111 1110 1111 +0 +1 +2 +3 +4 +5 +6 +7 -8 -7 -6 -5 -4 -3 -2

24 92 Overflow Detection in Two’s Complement 5 3 -8 0 1 0 1 0 0 1 1 -7 -2 7 1 0 0 1 1 1 1 0 527527 0 1 0 1 0 0 1 0 -3 -5 -8 1 1 0 1 1 0 1 1 Overflow No overflow Overflow when carry in to sign does not equal carry out

25 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

26 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

27 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

28 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

29 97 Half Adder With twos complement numbers, addition is sufficient Half-adder Schematic

30 98 Full Adder A 0 0 0 0 1 1 1 1 B 0 0 1 1 0 0 1 1 CI 0 1 0 1 0 1 0 1 S 0 1 1 0 1 0 0 1 CO 0 0 0 1 0 1 1 1

31 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

32 100 Multi-Bit Addition Cascaded Multi-bit Adder usually interested in adding more than two bits this motivates the need for the full adder

33 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


Download ppt "69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position."

Similar presentations


Ads by Google