Download presentation
Presentation is loading. Please wait.
Published byGrace Lewis Modified over 8 years ago
1
CPE 201 Digital Design Lecture 3: Digital Systems & Binary Numbers (3)
2
2 Lecture Outline Complement systems Arithmetic operations with binary numbers
3
3 Complements Goal: logicalmanipulation –simplify subtraction operation and logical manipulation Complement systems negate a number by taking its complement Two types of complements for each base-r system –Radix complement: r’s complement –Diminished radix complement: (r-1)’s complement Big advantage: allows us to perform subtraction using addition –Thus, only need adder component, no need for separate subtractor component!
4
4 Diminished Radix Complement The (r-1)’s complement of an n-digit number N = r n – 1 – N Decimal –r = 10 9’s complement of N is 10 n – 1 – N –10 n : a “1” followed by n “0”s –10 n – 1: a number given by n “9”s The 9’s complement of a digital number is obtained by subtracting each digit from 9
5
5 Examples: 9’s Complement E.g.: 9’s complement of 358433: 999999 – 358433 = 641566 850843:999999 – 850843 = 149156 573852:999999 - 573852 = 426147
6
6 Diminished Radix Complement – Radix 2 Binary –r = 2 1’s complement of N is 2 n – 1 – N –2 n : a “1” followed by n “0”s –2 n – 1: a number given by n “1”s The 1’s complement of a binary number is obtained by subtracting each digit from 1 Observation: 1-0 = 11-1 = 0 –Bit changes! The 1’s complement of a binary number is obtained by flipping the bits of the number
7
7 Examples: 1’s complement E.g.: 1’s complement of 11100101: 10010111: 00010001: 10011100: 01110111: 00000000: 00011010 01101000 11101110 01100011 10001000 11111111
8
8 Radix Complement The r’s complement of an n-digit number N = r n – N This means just adding 1 to the (r-1)’s complement! Decimal –Leave all LSB zeros unchanged –Subtract the first nonzero LSB from 10, subtract the rest from 9 Binary –Leave all LSB zeros and the first “1” unchanged –Flip the rest of the bits
9
9 Examples: 10’s Complement With addition: (1289, 2389, 5840, 3048) 1289: (9999-1289) + 1 = 8710 + 1 = 8711 2389: (9999-2389) + 1 = 7610 + 1 = 7611 5840: (9999-5840) + 1 = 4159 + 1 = 4160 3048:(9999-3048) + 1 = 6951 + 1 = 6952 With alternative rule 1289:8711 2389: 7611 5840: 4160 3048:6952
10
10 Examples: 2’s Complement With addition: ( 00010001, 10011101, 01110111, 00000000 ) 00010001: 11101110 + 1 = 11101111 10011101:01100010 + 1 = 01100011 01110111:10001000 + 1 = 10001001 00000000: 11111111 + 1 = 1 00000000 With alternative rule: (1101100, 0110111) 1101100:0010100 0110111:1001001 Carry ignored
11
11 Subtraction with r’s Complements Subtracting a number-done by adding its complement –Adding its complement results in answer exactly 10 more –Drop the 1 results in subtracting using addition only - - Exemplified with base 10 and 1-digit numbers
12
12 Subtraction with r’s Complements Compute M – N M – N = M + r’s complement (N) = M + r n – N = (M – N) + r n M>N: = (M – N) + r n M<N: = r n – (N – M) Carry to next digit: IGNORED! The r’s complement of the desired result with negative sign! Take the complement and add a negative sign.
13
13 Subtraction with r’s Complements To compute M – N: –Take the r’s complement of N –Add that value to M –Two cases can occur: A carry to next digit is obtained (M was greater than N) ignore the carry to get the result No carry is obtained (M was smaller than N) take the r’s complement of the resulted value and add a negative sign
14
14 Subtraction Using 10’s Complement 72532 – 3250 = 72532 + 96750 Result = 69282 3250 – 72532 = 03250 + 27468 Res. = -10’s complement(30718) = - 69282 Discard the carry No carry 692821 30718 Make sure you fill out to the maximum available number of digits! 0
15
15 Subtraction Using 2’s Complement X = 1010100Y = 1000011 X – Y = ?Y – X = ? X – Y:Y – X: 1010100+1000011+ 01111010101100 100100011101111 Res. = -2’s comp. (1101111) = -0010001 Discard the carry No carry
16
16 Subtraction with (r-1)’s Complements Compute M – N M – N = M + (r-1)’s complement (N) = M + r n – N – 1 = (M – N – 1) + r n M>N: = (M – N – 1) + r n M<N: = r n – 1 – (N – M) Carry to next digit: IGNORED! Got 1 less than result add 1 The (r-1)’s complement of the desired result with negative sign! Take the complement and add a negative sign.
17
17 Subtraction with (r-1)’s Complements To compute M – N: –Take the (r-1)’s complement of N –Add that value to M –Two cases can occur: A carry to next digit is obtained (M was greater than N) ignore the carry and add 1 to get the result No carry is obtained (M was smaller than N) take the (r-1)’s complement of the resulted value and add a negative sign
18
18 Subtraction Using 1’s Complement X = 1010100Y = 1000011 X – Y = ?Y – X = ? X – Y:Y – X: 1010100+1000011+ 01111000101011 10010000+1101110 1 10010001 -1’s complement of 1101110 = -0010001 Discard the carry No carry
19
19 Readings Chapter 1: –Sections 1.6, 1.7
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.