SlideShare une entreprise Scribd logo
1  sur  25
SYEN 3330 Digital Systems Jung H. Kim Chapter 5-2 1
SYEN 3330
Digital Systems
Chapter 5 – Part 2
SYEN 3330 Digital Systems Chapter 5-2 Page 2
Complements
• Subtraction of numbers requires a different algorithm
than addition.
• Adding a complement of a number is equivalent to
subtraction.
• We will discuss two complements:
Diminished Radix Complement
Radix Complement
• Subtraction will be accomplished by adding a
complement.
SYEN 3330 Digital Systems Chapter 5-2 Page 3
Diminished Radix Complement
Given a number N in Base r having n digits, the (r-1)'s
complement (called the Diminished Radix Complement) is
defined as:
(rn - 1) - N
Example:
For r = 10, N = 123410, n = 4 (4 digits),we have:
(rn - 1) = 10,000 -1 = 999910
The 9's complement of 123410 is then:
999910 - 123410 = 876510
SYEN 3330 Digital Systems Chapter 5-2 Page 4
Binary 1's Complement
For r = 2, N = 011100112, n = 8 (8 digits), we have:
(rn - 1) = 256 -1 = 25510 or 111111112
The 1's complement of 011100112 is then:
111111112
- 011100112
----------------
100011002
NOTE: Since the 2n-1 factor consists of all 1's and
since 1 - 0= 1 and 1 - 1 = 0, forming the one's
complement consists of complementing each
individual bit.
SYEN 3330 Digital Systems Chapter 5-2 Page 5
Radix Complement
Given a number N in Base r having n digits, the r's
complement (called the Radix Complement) is defined as:
rn - N for N  0 and
0 for N = 0
Note that the Radix Complement is obtained by adding 1
to the Diminished Radix Complement.
Example:
For r = 10, N = 123410, n = 4 (4 digits), we have:
rn = 10,00010
The 10's complement of 123410 is then
10,00010 - 123410 = 876610 or 8765 + 1 (9's complement plus 1)
SYEN 3330 Digital Systems Chapter 5-2 Page 6
Binary 2's Complement
For r = 2, N = 011100112, n = 8 (8 digits), we have:
(rn ) = 25610 or 1000000002
The 2's complement of 011100112 is then:
1000000002
- 011100112
----------------
100011012
Note that this is the 1's complement plus 1.
SYEN 3330 Digital Systems Chapter 5-2 Page 7
Binary 2's Complement Examples
100000000
- 11011100
-----------------
00100100
100000000
- 00000000
-----------------
00000000
(The 2's complement of 0 is zero!)
100000000
- 11111111  (could this be -1)?
-----------------
00000001  (could this be +1?)
SYEN 3330 Digital Systems Chapter 5-2 Page 8
Efficient 2’s Complement
an-1an-2 ai+110...00
Given: an n-bit binary number:
Where for some digit position i, ai is 1 and all digits to the
right are 0, form the twos complement value this way:
Leave ai equal to 1 (unchanged),
and
Leave rightmost digits 0 (unchanged),
and
` complement all other digits to the left of ai.
(0 replaces 1, 1 replaces 0)
SYEN 3330 Digital Systems Chapter 5-2 Page 9
Two's Complement Example
First 1 from right -----
Complement leftmost digits
------------------
10010100011100100000
------ Leave these
This  0110100111100
becomes 1001011000100
This  1000000000000
becomes 1000000000000
01101011100011100000
SYEN 3330 Digital Systems Chapter 5-2 Page 10
Subtraction with Radix Complements
Subtract two n-digit, unsigned numbers M  N,
in base r as follows:
1. Add the minuend M to the r's complement of the
subtrahend N to perform:
M + (r
n
- N) = M  N + r
n
2. If M  N, the sum will produce an end carry, rn
which is
discarded; what is left is the result, M  N.
3. If M < N, the sum does not produce an end carry and is
equal to rn
- ( N - M ), which is the r's complement of ( N 
M ). To obtain the answer in a familiar form, take the r's
complement of the sum and place a negative sign in front.
SYEN 3330 Digital Systems Chapter 5-2 Page 11
Example: Find 543
10
- 123
10
1). Form 10's complement of 123:
2). Add the two:
3). Since M > N, we discard the carry.
1000
- 123
-----------
877
543
(+) 877
-------------
1420
Ans: 420
SYEN 3330 Digital Systems Chapter 5-2 Page 12
Example: Find 123
10
- 543
10
1). Form 10's complement of 543:
2). Add the two:
3). Since M < N, form complement
1000
 543
-----------
457
123
(+) 457
-------------
580 (no carry)
1000
() 580
-----------
420
Answer is ()420.
SYEN 3330 Digital Systems Chapter 5-2 Page 13
Binary Example
Compute: 1010100 - 1000011
1). Form 2's complement of 1000011:
2). Add the two:
3). Since M  N, discard the carry.
1000011
0111101
1010100
0111101
(+) -------------
1 0010001 (a carry )
Ans. = 0010001
SYEN 3330 Digital Systems Chapter 5-2 Page 14
Another Binary Example
1). Form 2's complement of 1010100:
2). Add the two:
3). Since M < N, complement the result.
Compute: 1000011 - 1010100
1010100
0101100
1000011
0101100
(+) -------------
1101111 (no carry)
Ans. = () 0010001
SYEN 3330 Digital Systems Chapter 5-2 Page 15
Subtract: Add 1’s Complement
We can use addition of the 1's complement to subtract two
numbers with a minor modification.
Since (r-1)'s complement is one less than the r's
complement, the result produces a sum which is one less
than the correct sum when an end carry occurs.
We can simply add in the end carry when it occurs to
correct the answer.
If the end carry does not occur, the result is negative and
we can use the 1's complement to represent the negative
result.
SYEN 3330 Digital Systems Chapter 5-2 Page 16
1’s Complement Subtraction
Use 1's complement to compute 1010100 - 1000011
1). Form 1's complement of 1000011:
2). Add the two:
3). Add carry, end around
1000011
0111100
1010100
0111100
(+) -------------
10010000 (a carry)
(+) 0000001
-------------
0010001
Ans. = 0010001
SYEN 3330 Digital Systems Chapter 5-2 Page 17
1’s Complement Subtraction
Use 1's complement for computing 1000011 - 1010100
1). Form 1's complement of 1010100: 1010100
0101011
2). Add the two:
1000011
0101011
(+) -------------
1101110 (no carry)
3). Form 1's complement: 0010001
4). The answer has a negative sign.
Ans. = () 0010001
SYEN 3330 Digital Systems Chapter 5-2 Page 18
Signed Integers
Positive numbers and zero can be represented by unsigned n-
digit, radix r numbers. We need a representation for
negative numbers.
To represent a sign (+ or -) we need exactly one more bit of
information (1 binary digit gives 2
1
= 2 elements which is
exactly what is needed).
Since most computers use binary numbers, by convention,
(and for convenience), the most significant bit is interpreted
as a sign bit as shown below:
san-2  a2a1a0
Where: s = 0 for Positive numbers
s = 1 for Negative numbers
and ai are 0 or 1
SYEN 3330 Digital Systems Chapter 5-2 Page 19
Interpreting the Other Digits
Given n binary digits, the digit with weight 2(n-1) is the sign and the
digits with weights 2(n-2) down to 2(0) can be used to represent 2(n-
1) distinct elements.
There are several ways to interpret the other digits. Here are three
popular choices:
1. Signed-Magnitude -- here the n-1 digits are interpreted as a
positive magnitude.
2. Signed-Complement -- here the digits are interpreted as the rest of
the complement of the number. There are two possibilities here:
2a. Signed One's Complement --
(use the 1's Complement to compute)
2b. Signed Two's Complement --
(use the 2's Complement to compute)
SYEN 3330 Digital Systems Chapter 5-2 Page 20
Example: Given r=2, n=3
We have the following interpretations for signed integer
representation:
Number Sign-Mag. 1's Comp. 2's Comp.
+3 011 011 011
+2 010 010 010
+1 001 001 001
+0 000 000 000
-0 100 111 ---
-1 101 110 111
-2 110 101 110
-3 111 100 101
-4 --- --- 100
SYEN 3330 Digital Systems Chapter 5-2 Page 21
Addition with Signed Numbers
Caution: If you use all rn possible combinations of n
radix r digits, some operations on elements of the set
will produce elements which will not be represented in
the set.
Example: Add unsigned, 3-bit integers 1012 to 1002 to
get 10012 (5 + 4 = 9). This result cannot be represented
in the set of 3-bit unsigned integers. An overflow is said
to have occurred.
SYEN 3330 Digital Systems Chapter 5-2 Page 22
Signed-Magnitude Arithmetic
Addition:
If signs are the same:
1. Add the magnitudes.
2. Check for overflow (a carry into the sign bit).
3. The sign of the result is the same.
If the signs differ:
1. Subtract the magnitude of the smaller from the magnitude of
the larger.
2. Use the sign of the larger magnitude for the sign of the result.
3. Overflow will never occur.
Subtraction:
Complement the sign bit of the number you are subtracting and
follow the rules for addition.
SYEN 3330 Digital Systems Chapter 5-2 Page 23
Sign-Magnitude Examples
Same signs
000 + 001 = 001 (signs are the same)
010 + 010 = x00 (Overflow into sign bit)
101 + 101 = 110 (signs are the same)
110 + 110 = x00 (Overflow into sign bit)
Different signs
001 + 110 = 101 (010  001, take  sign)
111 + 010 = 101 (011  001, take  sign)
101 + 010 = 001 (010  001, take + sign)
100 + 000 = ?00 (is it + or - zero?)
SYEN 3330 Digital Systems Chapter 5-2 Page 24
Signed-Complement Arithmetic
Addition:
1. Add the numbers including the sign bits, discarding a
carry out of the sign bits (2's Complement), or using
an end-around carry (1's Complement).
2. If the sign bits were the same for both numbers and
the sign of the result is different, an overflow has
occurred.
3. The sign of the result is computed in step 1.
Subtraction:
Form the complement of the number you are subtracting
and follow the rules for addition.
SYEN 3330 Digital Systems Chapter 5-2 Page 25
Binary Adder/Subtractor
Subtraction can be accomplished by addition of the Two's
Complement. Thus we::
1. Complement each bit (One's Comp.)
2. Add one to the result.
The following circuit computes A - B:
It computes A - B when
the Carry-In is "1" by
forming the One's
Complement of B using
EXOR gates and adding
one
Co Ci
x y
S
FA
A(3)
B(3)
S(3)
Co Ci
x y
S
FA
B(2)
S(2)
Co Ci
x y
S
FA
B(1)
S(1)
Co Ci
x y
S
FA
S(0)
B(0)
A(2) A(1) A(0)
C(4) C(3) C(2) C(1)
C(0)

Contenu connexe

Similaire à Lecture_5-2.ppt

Chapter 1 digital systems and binary numbers
Chapter 1 digital systems and binary numbersChapter 1 digital systems and binary numbers
Chapter 1 digital systems and binary numbersMohammad Bashartullah
 
chapter1digitalsystemsandbinarynumbers-151021072016-lva1-app6891.pptx
chapter1digitalsystemsandbinarynumbers-151021072016-lva1-app6891.pptxchapter1digitalsystemsandbinarynumbers-151021072016-lva1-app6891.pptx
chapter1digitalsystemsandbinarynumbers-151021072016-lva1-app6891.pptxSurendra Loya
 
Chapter_1_Digital_Systems_and_Binary_Numbers2.ppt
Chapter_1_Digital_Systems_and_Binary_Numbers2.pptChapter_1_Digital_Systems_and_Binary_Numbers2.ppt
Chapter_1_Digital_Systems_and_Binary_Numbers2.pptDavid Louie Bedia
 
Mba admission in india
Mba admission in indiaMba admission in india
Mba admission in indiaEdhole.com
 
Computer organiztion2
Computer organiztion2Computer organiztion2
Computer organiztion2Umang Gupta
 
digital-systems-and-binary-numbers1.pptx
digital-systems-and-binary-numbers1.pptxdigital-systems-and-binary-numbers1.pptx
digital-systems-and-binary-numbers1.pptxRameshK531901
 
Digital logic and design 02
Digital logic and design 02Digital logic and design 02
Digital logic and design 02ranjit shrestha
 
Complement in DLD
Complement in DLDComplement in DLD
Complement in DLDshahzad ali
 
Switching circuits and logic design
Switching circuits and logic designSwitching circuits and logic design
Switching circuits and logic designgoutamkrsahoo
 
digital-electronics.pptx
digital-electronics.pptxdigital-electronics.pptx
digital-electronics.pptxsulekhasaxena2
 
About the computer of the important field
About the computer               of the important fieldAbout the computer               of the important field
About the computer of the important fieldshubhamgupta7133
 
Digital_Electronics_Basics.pdf
Digital_Electronics_Basics.pdfDigital_Electronics_Basics.pdf
Digital_Electronics_Basics.pdfrahul143341
 
Number system and codes
Number system and codesNumber system and codes
Number system and codesAbhiraj Bohra
 
B sc cs i bo-de u-i number system
B sc cs i bo-de u-i number systemB sc cs i bo-de u-i number system
B sc cs i bo-de u-i number systemRai University
 
UNIT - I.pptx
UNIT - I.pptxUNIT - I.pptx
UNIT - I.pptxamudhak10
 
UNIT - I.pptx
UNIT - I.pptxUNIT - I.pptx
UNIT - I.pptxamudhak10
 

Similaire à Lecture_5-2.ppt (20)

DATA REPRESENTATION
DATA  REPRESENTATIONDATA  REPRESENTATION
DATA REPRESENTATION
 
Chapter 1 digital systems and binary numbers
Chapter 1 digital systems and binary numbersChapter 1 digital systems and binary numbers
Chapter 1 digital systems and binary numbers
 
chapter1digitalsystemsandbinarynumbers-151021072016-lva1-app6891.pptx
chapter1digitalsystemsandbinarynumbers-151021072016-lva1-app6891.pptxchapter1digitalsystemsandbinarynumbers-151021072016-lva1-app6891.pptx
chapter1digitalsystemsandbinarynumbers-151021072016-lva1-app6891.pptx
 
Complements
ComplementsComplements
Complements
 
Chapter_1_Digital_Systems_and_Binary_Numbers2.ppt
Chapter_1_Digital_Systems_and_Binary_Numbers2.pptChapter_1_Digital_Systems_and_Binary_Numbers2.ppt
Chapter_1_Digital_Systems_and_Binary_Numbers2.ppt
 
Lec20
Lec20Lec20
Lec20
 
Mba admission in india
Mba admission in indiaMba admission in india
Mba admission in india
 
Computer organiztion2
Computer organiztion2Computer organiztion2
Computer organiztion2
 
digital-systems-and-binary-numbers1.pptx
digital-systems-and-binary-numbers1.pptxdigital-systems-and-binary-numbers1.pptx
digital-systems-and-binary-numbers1.pptx
 
Digital logic and design 02
Digital logic and design 02Digital logic and design 02
Digital logic and design 02
 
Complement in DLD
Complement in DLDComplement in DLD
Complement in DLD
 
Switching circuits and logic design
Switching circuits and logic designSwitching circuits and logic design
Switching circuits and logic design
 
Okkkkk
OkkkkkOkkkkk
Okkkkk
 
digital-electronics.pptx
digital-electronics.pptxdigital-electronics.pptx
digital-electronics.pptx
 
About the computer of the important field
About the computer               of the important fieldAbout the computer               of the important field
About the computer of the important field
 
Digital_Electronics_Basics.pdf
Digital_Electronics_Basics.pdfDigital_Electronics_Basics.pdf
Digital_Electronics_Basics.pdf
 
Number system and codes
Number system and codesNumber system and codes
Number system and codes
 
B sc cs i bo-de u-i number system
B sc cs i bo-de u-i number systemB sc cs i bo-de u-i number system
B sc cs i bo-de u-i number system
 
UNIT - I.pptx
UNIT - I.pptxUNIT - I.pptx
UNIT - I.pptx
 
UNIT - I.pptx
UNIT - I.pptxUNIT - I.pptx
UNIT - I.pptx
 

Dernier

➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...amitlee9823
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Detecting Credit Card Fraud: A Machine Learning Approach
Detecting Credit Card Fraud: A Machine Learning ApproachDetecting Credit Card Fraud: A Machine Learning Approach
Detecting Credit Card Fraud: A Machine Learning ApproachBoston Institute of Analytics
 
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...karishmasinghjnh
 
Just Call Vip call girls roorkee Escorts ☎️9352988975 Two shot with one girl ...
Just Call Vip call girls roorkee Escorts ☎️9352988975 Two shot with one girl ...Just Call Vip call girls roorkee Escorts ☎️9352988975 Two shot with one girl ...
Just Call Vip call girls roorkee Escorts ☎️9352988975 Two shot with one girl ...gajnagarg
 
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -Pooja Nehwal
 
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...Elaine Werffeli
 
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteedamy56318795
 
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...amitlee9823
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men 🔝Ongole🔝 Escorts S...
➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men  🔝Ongole🔝   Escorts S...➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men  🔝Ongole🔝   Escorts S...
➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men 🔝Ongole🔝 Escorts S...amitlee9823
 
Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...
Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...
Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...gajnagarg
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Valters Lauzums
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...amitlee9823
 
➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men 🔝Sambalpur🔝 Esc...
➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men  🔝Sambalpur🔝   Esc...➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men  🔝Sambalpur🔝   Esc...
➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men 🔝Sambalpur🔝 Esc...amitlee9823
 

Dernier (20)

➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
 
Detecting Credit Card Fraud: A Machine Learning Approach
Detecting Credit Card Fraud: A Machine Learning ApproachDetecting Credit Card Fraud: A Machine Learning Approach
Detecting Credit Card Fraud: A Machine Learning Approach
 
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
 
Just Call Vip call girls roorkee Escorts ☎️9352988975 Two shot with one girl ...
Just Call Vip call girls roorkee Escorts ☎️9352988975 Two shot with one girl ...Just Call Vip call girls roorkee Escorts ☎️9352988975 Two shot with one girl ...
Just Call Vip call girls roorkee Escorts ☎️9352988975 Two shot with one girl ...
 
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
 
Predicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science ProjectPredicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science Project
 
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
 
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
 
Anomaly detection and data imputation within time series
Anomaly detection and data imputation within time seriesAnomaly detection and data imputation within time series
Anomaly detection and data imputation within time series
 
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
 
➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men 🔝Ongole🔝 Escorts S...
➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men  🔝Ongole🔝   Escorts S...➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men  🔝Ongole🔝   Escorts S...
➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men 🔝Ongole🔝 Escorts S...
 
Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...
Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...
Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
 
➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men 🔝Sambalpur🔝 Esc...
➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men  🔝Sambalpur🔝   Esc...➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men  🔝Sambalpur🔝   Esc...
➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men 🔝Sambalpur🔝 Esc...
 

Lecture_5-2.ppt

  • 1. SYEN 3330 Digital Systems Jung H. Kim Chapter 5-2 1 SYEN 3330 Digital Systems Chapter 5 – Part 2
  • 2. SYEN 3330 Digital Systems Chapter 5-2 Page 2 Complements • Subtraction of numbers requires a different algorithm than addition. • Adding a complement of a number is equivalent to subtraction. • We will discuss two complements: Diminished Radix Complement Radix Complement • Subtraction will be accomplished by adding a complement.
  • 3. SYEN 3330 Digital Systems Chapter 5-2 Page 3 Diminished Radix Complement Given a number N in Base r having n digits, the (r-1)'s complement (called the Diminished Radix Complement) is defined as: (rn - 1) - N Example: For r = 10, N = 123410, n = 4 (4 digits),we have: (rn - 1) = 10,000 -1 = 999910 The 9's complement of 123410 is then: 999910 - 123410 = 876510
  • 4. SYEN 3330 Digital Systems Chapter 5-2 Page 4 Binary 1's Complement For r = 2, N = 011100112, n = 8 (8 digits), we have: (rn - 1) = 256 -1 = 25510 or 111111112 The 1's complement of 011100112 is then: 111111112 - 011100112 ---------------- 100011002 NOTE: Since the 2n-1 factor consists of all 1's and since 1 - 0= 1 and 1 - 1 = 0, forming the one's complement consists of complementing each individual bit.
  • 5. SYEN 3330 Digital Systems Chapter 5-2 Page 5 Radix Complement Given a number N in Base r having n digits, the r's complement (called the Radix Complement) is defined as: rn - N for N  0 and 0 for N = 0 Note that the Radix Complement is obtained by adding 1 to the Diminished Radix Complement. Example: For r = 10, N = 123410, n = 4 (4 digits), we have: rn = 10,00010 The 10's complement of 123410 is then 10,00010 - 123410 = 876610 or 8765 + 1 (9's complement plus 1)
  • 6. SYEN 3330 Digital Systems Chapter 5-2 Page 6 Binary 2's Complement For r = 2, N = 011100112, n = 8 (8 digits), we have: (rn ) = 25610 or 1000000002 The 2's complement of 011100112 is then: 1000000002 - 011100112 ---------------- 100011012 Note that this is the 1's complement plus 1.
  • 7. SYEN 3330 Digital Systems Chapter 5-2 Page 7 Binary 2's Complement Examples 100000000 - 11011100 ----------------- 00100100 100000000 - 00000000 ----------------- 00000000 (The 2's complement of 0 is zero!) 100000000 - 11111111  (could this be -1)? ----------------- 00000001  (could this be +1?)
  • 8. SYEN 3330 Digital Systems Chapter 5-2 Page 8 Efficient 2’s Complement an-1an-2 ai+110...00 Given: an n-bit binary number: Where for some digit position i, ai is 1 and all digits to the right are 0, form the twos complement value this way: Leave ai equal to 1 (unchanged), and Leave rightmost digits 0 (unchanged), and ` complement all other digits to the left of ai. (0 replaces 1, 1 replaces 0)
  • 9. SYEN 3330 Digital Systems Chapter 5-2 Page 9 Two's Complement Example First 1 from right ----- Complement leftmost digits ------------------ 10010100011100100000 ------ Leave these This  0110100111100 becomes 1001011000100 This  1000000000000 becomes 1000000000000 01101011100011100000
  • 10. SYEN 3330 Digital Systems Chapter 5-2 Page 10 Subtraction with Radix Complements Subtract two n-digit, unsigned numbers M  N, in base r as follows: 1. Add the minuend M to the r's complement of the subtrahend N to perform: M + (r n - N) = M  N + r n 2. If M  N, the sum will produce an end carry, rn which is discarded; what is left is the result, M  N. 3. If M < N, the sum does not produce an end carry and is equal to rn - ( N - M ), which is the r's complement of ( N  M ). To obtain the answer in a familiar form, take the r's complement of the sum and place a negative sign in front.
  • 11. SYEN 3330 Digital Systems Chapter 5-2 Page 11 Example: Find 543 10 - 123 10 1). Form 10's complement of 123: 2). Add the two: 3). Since M > N, we discard the carry. 1000 - 123 ----------- 877 543 (+) 877 ------------- 1420 Ans: 420
  • 12. SYEN 3330 Digital Systems Chapter 5-2 Page 12 Example: Find 123 10 - 543 10 1). Form 10's complement of 543: 2). Add the two: 3). Since M < N, form complement 1000  543 ----------- 457 123 (+) 457 ------------- 580 (no carry) 1000 () 580 ----------- 420 Answer is ()420.
  • 13. SYEN 3330 Digital Systems Chapter 5-2 Page 13 Binary Example Compute: 1010100 - 1000011 1). Form 2's complement of 1000011: 2). Add the two: 3). Since M  N, discard the carry. 1000011 0111101 1010100 0111101 (+) ------------- 1 0010001 (a carry ) Ans. = 0010001
  • 14. SYEN 3330 Digital Systems Chapter 5-2 Page 14 Another Binary Example 1). Form 2's complement of 1010100: 2). Add the two: 3). Since M < N, complement the result. Compute: 1000011 - 1010100 1010100 0101100 1000011 0101100 (+) ------------- 1101111 (no carry) Ans. = () 0010001
  • 15. SYEN 3330 Digital Systems Chapter 5-2 Page 15 Subtract: Add 1’s Complement We can use addition of the 1's complement to subtract two numbers with a minor modification. Since (r-1)'s complement is one less than the r's complement, the result produces a sum which is one less than the correct sum when an end carry occurs. We can simply add in the end carry when it occurs to correct the answer. If the end carry does not occur, the result is negative and we can use the 1's complement to represent the negative result.
  • 16. SYEN 3330 Digital Systems Chapter 5-2 Page 16 1’s Complement Subtraction Use 1's complement to compute 1010100 - 1000011 1). Form 1's complement of 1000011: 2). Add the two: 3). Add carry, end around 1000011 0111100 1010100 0111100 (+) ------------- 10010000 (a carry) (+) 0000001 ------------- 0010001 Ans. = 0010001
  • 17. SYEN 3330 Digital Systems Chapter 5-2 Page 17 1’s Complement Subtraction Use 1's complement for computing 1000011 - 1010100 1). Form 1's complement of 1010100: 1010100 0101011 2). Add the two: 1000011 0101011 (+) ------------- 1101110 (no carry) 3). Form 1's complement: 0010001 4). The answer has a negative sign. Ans. = () 0010001
  • 18. SYEN 3330 Digital Systems Chapter 5-2 Page 18 Signed Integers Positive numbers and zero can be represented by unsigned n- digit, radix r numbers. We need a representation for negative numbers. To represent a sign (+ or -) we need exactly one more bit of information (1 binary digit gives 2 1 = 2 elements which is exactly what is needed). Since most computers use binary numbers, by convention, (and for convenience), the most significant bit is interpreted as a sign bit as shown below: san-2  a2a1a0 Where: s = 0 for Positive numbers s = 1 for Negative numbers and ai are 0 or 1
  • 19. SYEN 3330 Digital Systems Chapter 5-2 Page 19 Interpreting the Other Digits Given n binary digits, the digit with weight 2(n-1) is the sign and the digits with weights 2(n-2) down to 2(0) can be used to represent 2(n- 1) distinct elements. There are several ways to interpret the other digits. Here are three popular choices: 1. Signed-Magnitude -- here the n-1 digits are interpreted as a positive magnitude. 2. Signed-Complement -- here the digits are interpreted as the rest of the complement of the number. There are two possibilities here: 2a. Signed One's Complement -- (use the 1's Complement to compute) 2b. Signed Two's Complement -- (use the 2's Complement to compute)
  • 20. SYEN 3330 Digital Systems Chapter 5-2 Page 20 Example: Given r=2, n=3 We have the following interpretations for signed integer representation: Number Sign-Mag. 1's Comp. 2's Comp. +3 011 011 011 +2 010 010 010 +1 001 001 001 +0 000 000 000 -0 100 111 --- -1 101 110 111 -2 110 101 110 -3 111 100 101 -4 --- --- 100
  • 21. SYEN 3330 Digital Systems Chapter 5-2 Page 21 Addition with Signed Numbers Caution: If you use all rn possible combinations of n radix r digits, some operations on elements of the set will produce elements which will not be represented in the set. Example: Add unsigned, 3-bit integers 1012 to 1002 to get 10012 (5 + 4 = 9). This result cannot be represented in the set of 3-bit unsigned integers. An overflow is said to have occurred.
  • 22. SYEN 3330 Digital Systems Chapter 5-2 Page 22 Signed-Magnitude Arithmetic Addition: If signs are the same: 1. Add the magnitudes. 2. Check for overflow (a carry into the sign bit). 3. The sign of the result is the same. If the signs differ: 1. Subtract the magnitude of the smaller from the magnitude of the larger. 2. Use the sign of the larger magnitude for the sign of the result. 3. Overflow will never occur. Subtraction: Complement the sign bit of the number you are subtracting and follow the rules for addition.
  • 23. SYEN 3330 Digital Systems Chapter 5-2 Page 23 Sign-Magnitude Examples Same signs 000 + 001 = 001 (signs are the same) 010 + 010 = x00 (Overflow into sign bit) 101 + 101 = 110 (signs are the same) 110 + 110 = x00 (Overflow into sign bit) Different signs 001 + 110 = 101 (010  001, take  sign) 111 + 010 = 101 (011  001, take  sign) 101 + 010 = 001 (010  001, take + sign) 100 + 000 = ?00 (is it + or - zero?)
  • 24. SYEN 3330 Digital Systems Chapter 5-2 Page 24 Signed-Complement Arithmetic Addition: 1. Add the numbers including the sign bits, discarding a carry out of the sign bits (2's Complement), or using an end-around carry (1's Complement). 2. If the sign bits were the same for both numbers and the sign of the result is different, an overflow has occurred. 3. The sign of the result is computed in step 1. Subtraction: Form the complement of the number you are subtracting and follow the rules for addition.
  • 25. SYEN 3330 Digital Systems Chapter 5-2 Page 25 Binary Adder/Subtractor Subtraction can be accomplished by addition of the Two's Complement. Thus we:: 1. Complement each bit (One's Comp.) 2. Add one to the result. The following circuit computes A - B: It computes A - B when the Carry-In is "1" by forming the One's Complement of B using EXOR gates and adding one Co Ci x y S FA A(3) B(3) S(3) Co Ci x y S FA B(2) S(2) Co Ci x y S FA B(1) S(1) Co Ci x y S FA S(0) B(0) A(2) A(1) A(0) C(4) C(3) C(2) C(1) C(0)