SlideShare une entreprise Scribd logo
1  sur  14
Télécharger pour lire hors ligne
3/28/2012
1
Digital Logic & Design
Dr. Sajjad Ahmed Nadeem
Department of Computer Science & IT
University of Azad Jammu & Kashmir
Muzaffarabad
Module 02_01
Complements.
The (r-1)’s Complement.
The r’s Complement.
Subtraction with Complements.
3/28/2012
2
Complements (1)
Used in digital computers for
◦ simplifying the subtraction operation
◦ logical manipulations.
There are two types of complements for each base-r
system:
1. The (r – 1)’s Complement (Diminished radix complement).
2. The r’s Complement (Radix complement).
For Decimal numbers we have 9’s and 10’s complement
For Binary numbers we have 1’s and 2’s complement
Complements (2)
Complements of numbers with fractions
1. Remove the radix point
2. Obtain the complement
3. Return the radix point to its position
3/28/2012
3
The (r – 1)’s Complement (1)
Let X be a positive number in base r with n
digits, the (r – 1)’s complement of X is defined
as
(rⁿ - 1) – X
For r=10, it is called 9’s complement and
is given by (10ⁿ - 1) – X
For r=2, it is called 1’s complement and is
given by (2ⁿ - 1) – X
The (r – 1)’s Complement (2)
The 9’s complement of (52520)10 is
{(105 – 1) – 52520} = 99999 – 52520 = 47479.
The 9’s complement of (0.3267)10 is
{(104 – 1) – 3267} = 9999 – 3267 = 6732.
(Answer is 0.6732.)
The 9’s complement of (25.639)10 is
(105– 1– 25639) = 99999 – 25639 = 74360.
(Answer is 74.360.)
3/28/2012
4
The (r – 1)’s Complement (3)
The 1’s complement of (101100)2 is
(26 – 1) 10 – (101100)2 = (111111 – 101100)2 =
010011.
The 1’s complement of (0.0110)2 is
(24 – 1)10 – (0110)2 = (1111 – 0110)2 = 1001.
(Answer is 0.1001)
The 1’s complement of (100.0110)2 is
(27 – 1)10 – (1000110)2 = (1111111 –
1000110)2 = 0111001.
(Answer is 011.1001)
The (r – 1)’s Complement (4)
The 9’s complement of a decimal number
is formed simply by subtracting every digit
from 9.
The 1’s complement of a binary number is
simpler to form: the 1’s are changed to 0’s
and 0’s to 1’s.
3/28/2012
5
The r’s Complement (1)
Let X be a positive number in base r with n
digits, the r’s complement of X is defined as
rⁿ – X for X ≠ 0
0 for X = 0
For r=10, it is called 10’s complement and
is given by 10ⁿ – X = (10ⁿ – 1) – X + 1
For r=2, it is called 2’s complement and is
given by 2ⁿ – X = (2ⁿ – 1) – X + 1
The r’s Complement (1)
The 10’s complement of (52520)10 is
(105 – 1) – 52520 + 1 = 47480.
(The number of digits in the number is n=5.)
The 10’s complement of (0.3267)10 is
(104 – 1) – 3267 + 1 = 6733
(Answer is 0.6733)
The 10’s complement of (25.639)10 is
(105 – 1) – 25639 + 1= 74361
(Answer is 74.361)
3/28/2012
6
The r’s Complement (2)
The 2’s Complement of (101100)2 is
{(26 – 1)10 – (101100)2 }+ 1
= (111111 – 101100)+1
= 010100.
The 2’s Complement of (0.0110)2 is
{(24 – 1)10 – (0110)2 }+ 1
= 1010.
(Answer is 0.1010)
The r’s Complement (3)
10’s complement can be formed by
◦ leaving all least significant zeros unchanged and
◦ then subtracting the first non-zero least significant
digit from 10, and
◦ then subtracting all other higher significant digits from
9.
The 2’s Complement can be formed by
◦ leaving all least significant zeros and first non zero
digit unchanged, and
◦ then replacing 1’s by 0’s and 0’s by 1’s in all other
higher significant digits.
3/28/2012
7
Complement of Complement
The complement of complement restores
the number to its original value.
The r’s complement of N is rⁿ - N.
Therefore, the complement of (rⁿ - N) is
rⁿ - (rⁿ - N)
= N
Subtraction with r’s compliment (1)
The subtraction of two positive numbers (M – N), both
of base r, may be done as follows.
1. Add the minuend M to the r’s complement of
subtrahend N.
M – N =M+ r’s complement (N)
2. Inspect the result obtained in step 1 for an end carry:
(a) If an end carry occurs discard it.
(b) If an end carry does not occur, take the r’s
complement of the number obtained in step 1, and
place a negative sign in front.
3/28/2012
8
Subtraction with r’s compliment (2)
Using 10’s complement,subtract 72532 – 3250.
M = 72532 , N = 03250.
10’s complement of subtrahend N = 96750.
Step 1: 72532
+ 96750
End Carry 1 69282
Step 2, discard carry.
Answer = 69282.
Subtraction with r’s compliment (3)
Subtract: (3250 – 72532)10
M = 03250,N = 72532.
10’s complement of N = 27468.
Step 1: 03250
+ 27468
30718 (No End Carry)
Step 2:Answer = - (10’s complement of 30718)
Answer = - 69282
3/28/2012
9
Subtraction with r’s compliment (4)
Using 2’s complement, subtract 1010100 –
1000100.
M = 1010100,N = 1000100.
2’s complement of N = 0111100
Step 1: 1010100
+ 0111100
End Carry 1 0010000
Step 2: Discard Carry.
Answer = 0010000
Subtraction with r’s compliment (5)
Using 2’s complement, subtract 1000100 –
1010100.
M = 1000100,N = 1010100.
2’s complement of N = 0101100
Step 1: 1000100
+ 0101100
No Carry 1110000
Step 2:Answer = - (2’s complement of 1110000)
Answer = - 0010000
3/28/2012
10
Subtraction with (r – 1)’s compliment (1)
The procedure for subtraction with the (r – 1)’s
complement is exactly the same as the one used with r’s
compliment except for one variation, called “end-round
carry”.
The subtraction of two positive numbers (M – N), both of
base r, may be done as follows.
1. Add the minuend M to the (r – 1)’s complement of the
subtrahend N.
M – N =M+ (r – 1)’s complement (N)
2. Inspect the result obtained in step 1 for an End carry.
(a) If an end carry occurs, add 1 to the least significant
digit ( end-around carry).
(b) If an end carry does not occur, take the (r – 1)’s
complement of the number obtained in step 1 and place
a negative sign in front.
Using 9’s complement, subtract 72532 – 3250.
M = 72532 , N = 03250.
9’s complement of subtrahend N = 96749.
Step 1: 72532
+ 96749
End-around Carry 1 69281
Step 2,add end around carry. + 1
Answer = 69282
Subtraction with (r – 1)’s compliment (2)
3/28/2012
11
Subtract: (3250 – 72532)10
M = 03250,N = 72532.
9’s complement of N = 27467.
Step 1: 03250
+ 27467
30717 (No End Carry)
Step 2:Answer = - (9’s complement of 30717)
Answer = - 69282
Subtraction with (r – 1)’s compliment (3)
Using 1’s complement, subtract 1010100 –
1000100.
M = 1010100,N = 1000100.
1’s complement of N = 0111011
Step 1: 1010100
+ 0111011
End Carry 1 0001111
Step 2 + 1
Answer = 0010000
Subtraction with (r – 1)’s compliment (4)
3/28/2012
12
Using 1’s complement, subtract 1000100 –
1010100.
M = 1000100,N = 1010100.
1’s complement of N = 0101011
Step 1: 1000100
+ 0101011
No Carry 1101111
Step 2:Answer = - (1’s complement of 1101111)
Answer = - 10000
Subtraction with (r – 1)’s compliment (5)
Signed Binary Numbers (1)
We have one way to represent a positive number
(say +9)
Three ways to represent a negative numbers (say -9)
Sign Bit
◦ Signed-magnitude representation 1 0001001
◦ Signed-1’s complement representation 1 1110110
◦ Signed-2’s complement representation 1 1110111
3/28/2012
13
Signed Binary Numbers (2)
Signed Binary Numbers-Addition
Addition of two numbers in signed magnitude system
follow the same rules of ordinary arithmatic.
The addition of two signed binary numbers
◦ Use binary representation of the numbers and add them
◦ In case of negative number, add the 2’s complement of the negative
number to the positive number alongwith sign bits
◦ Add the 2’s complement of the negative numbers
◦ A carry out of the sign bit position is discarded
◦ If the sum obtained is in negative it is automatically in 2’s
complement form.
3/28/2012
14
Signed Binary Numbers-Subtraction
Take the 2’s complement of the subtrahed (including the
sign bit)
Add the obtained 2’s complement to the minuend
(including the sign bit).
A carry out of sign bit is discarded
Assignment
r’s complement for octal & hexadecimal
(r-1)’s complement for octal &
hexadecimal
Comparison between 1’s and 2’s
Complement.

Contenu connexe

Tendances

Integer Representation
Integer RepresentationInteger Representation
Integer Representation
gavhays
 
algebraic&transdential equations
algebraic&transdential equationsalgebraic&transdential equations
algebraic&transdential equations
8laddu8
 

Tendances (20)

Encoder, decoder, multiplexers and demultiplexers
Encoder, decoder, multiplexers and demultiplexersEncoder, decoder, multiplexers and demultiplexers
Encoder, decoder, multiplexers and demultiplexers
 
Parity Generator and Parity Checker
Parity Generator and Parity CheckerParity Generator and Parity Checker
Parity Generator and Parity Checker
 
Introduction to Half and Full Adder Circuit - Part 01 | Digital Logic Design |
Introduction to Half and Full Adder Circuit - Part 01 | Digital Logic Design |Introduction to Half and Full Adder Circuit - Part 01 | Digital Logic Design |
Introduction to Half and Full Adder Circuit - Part 01 | Digital Logic Design |
 
Digital Logic Design.pptx
Digital Logic Design.pptxDigital Logic Design.pptx
Digital Logic Design.pptx
 
Complement in DLD
Complement in DLDComplement in DLD
Complement in DLD
 
K - Map
  K - Map    K - Map
K - Map
 
Planar graph( Algorithm and Application )
Planar graph( Algorithm and Application )Planar graph( Algorithm and Application )
Planar graph( Algorithm and Application )
 
Number system in Digital Electronics
Number system in Digital ElectronicsNumber system in Digital Electronics
Number system in Digital Electronics
 
Presentation on Karnaugh Map
Presentation  on Karnaugh MapPresentation  on Karnaugh Map
Presentation on Karnaugh Map
 
8085 arithmetic instructions
8085 arithmetic instructions8085 arithmetic instructions
8085 arithmetic instructions
 
Number system conversion
Number system conversionNumber system conversion
Number system conversion
 
SOP POS, Minterm and Maxterm
SOP POS, Minterm and MaxtermSOP POS, Minterm and Maxterm
SOP POS, Minterm and Maxterm
 
Integer Representation
Integer RepresentationInteger Representation
Integer Representation
 
HDLC
HDLCHDLC
HDLC
 
Digital Logic circuit
Digital Logic circuitDigital Logic circuit
Digital Logic circuit
 
Differential Equation and its Application in LR circuit
Differential Equation and its Application in LR circuitDifferential Equation and its Application in LR circuit
Differential Equation and its Application in LR circuit
 
Assembly Language Basics
Assembly Language BasicsAssembly Language Basics
Assembly Language Basics
 
Binary Arithmetic Operations
Binary Arithmetic OperationsBinary Arithmetic Operations
Binary Arithmetic Operations
 
Power series
Power seriesPower series
Power series
 
algebraic&transdential equations
algebraic&transdential equationsalgebraic&transdential equations
algebraic&transdential equations
 

En vedette

En vedette (20)

Dld lecture module 01
Dld lecture module 01Dld lecture module 01
Dld lecture module 01
 
Basic+machine+organization
Basic+machine+organizationBasic+machine+organization
Basic+machine+organization
 
English 01 application
English 01 applicationEnglish 01 application
English 01 application
 
Number+system (1)
Number+system (1)Number+system (1)
Number+system (1)
 
Dld lecture module 06
Dld lecture module 06Dld lecture module 06
Dld lecture module 06
 
Graphical programming
Graphical programmingGraphical programming
Graphical programming
 
Uncdtalk
UncdtalkUncdtalk
Uncdtalk
 
Dld lecture module 03
Dld lecture module 03Dld lecture module 03
Dld lecture module 03
 
Operating Systems
Operating SystemsOperating Systems
Operating Systems
 
Artificial intelligence
Artificial intelligenceArtificial intelligence
Artificial intelligence
 
Chapter10
Chapter10Chapter10
Chapter10
 
Dld lecture module 05
Dld lecture module 05Dld lecture module 05
Dld lecture module 05
 
Algorithm defination, design & Implementation
Algorithm defination, design & ImplementationAlgorithm defination, design & Implementation
Algorithm defination, design & Implementation
 
Good
GoodGood
Good
 
Dld lecture module 04 01
Dld lecture module 04  01Dld lecture module 04  01
Dld lecture module 04 01
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Internet
InternetInternet
Internet
 
Okkkkk
OkkkkkOkkkkk
Okkkkk
 
An introduction to software
An introduction to softwareAn introduction to software
An introduction to software
 
Notes of programming
Notes of programmingNotes of programming
Notes of programming
 

Similaire à Dld lecture module 02

Number System 123.ppt is for binary number system
Number System 123.ppt is for binary number systemNumber System 123.ppt is for binary number system
Number System 123.ppt is for binary number system
drpreetiwctm
 
chapter1digitalsystemsandbinarynumbers-151021072016-lva1-app6891.pptx
chapter1digitalsystemsandbinarynumbers-151021072016-lva1-app6891.pptxchapter1digitalsystemsandbinarynumbers-151021072016-lva1-app6891.pptx
chapter1digitalsystemsandbinarynumbers-151021072016-lva1-app6891.pptx
Surendra Loya
 

Similaire à Dld lecture module 02 (20)

Lecture_5-2.ppt
Lecture_5-2.pptLecture_5-2.ppt
Lecture_5-2.ppt
 
Digital logic and design 02
Digital logic and design 02Digital logic and design 02
Digital logic and design 02
 
Number System 123.ppt is for binary number system
Number System 123.ppt is for binary number systemNumber System 123.ppt is for binary number system
Number System 123.ppt is for binary number system
 
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
 
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
 
Lec20
Lec20Lec20
Lec20
 
Application of bases
Application of basesApplication of bases
Application of bases
 
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
 
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
 
Switching circuits and logic design
Switching circuits and logic designSwitching circuits and logic design
Switching circuits and logic design
 
Data representation
Data representationData representation
Data representation
 
Number System
Number SystemNumber System
Number System
 
digital-electronics.pptx
digital-electronics.pptxdigital-electronics.pptx
digital-electronics.pptx
 
Data representation and Arithmetic Algorithms
Data representation and Arithmetic AlgorithmsData representation and Arithmetic Algorithms
Data representation and Arithmetic Algorithms
 
Number system
Number systemNumber system
Number system
 
Comp Arithmetic Basic.ppt
Comp Arithmetic Basic.pptComp Arithmetic Basic.ppt
Comp Arithmetic Basic.ppt
 
Binary Arithmetic
Binary ArithmeticBinary Arithmetic
Binary Arithmetic
 
Akash Saha CSE 33 ADEpptx.pptx
Akash Saha CSE 33 ADEpptx.pptxAkash Saha CSE 33 ADEpptx.pptx
Akash Saha CSE 33 ADEpptx.pptx
 
Module 1 number systems and code1
Module 1  number systems and code1Module 1  number systems and code1
Module 1 number systems and code1
 

Plus de Bilal Maqbool ツ

Plus de Bilal Maqbool ツ (19)

Lecture 3 report writtng
Lecture 3 report writtngLecture 3 report writtng
Lecture 3 report writtng
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Lecture 1 report writing
Lecture 1 report writingLecture 1 report writing
Lecture 1 report writing
 
Bill gates
Bill gatesBill gates
Bill gates
 
Programming assignment 02 (bilal maqbool 10) 2011
Programming assignment 02    (bilal maqbool 10) 2011Programming assignment 02    (bilal maqbool 10) 2011
Programming assignment 02 (bilal maqbool 10) 2011
 
Programming assignment 30 12-11
Programming assignment 30 12-11Programming assignment 30 12-11
Programming assignment 30 12-11
 
Internet presentation
Internet presentationInternet presentation
Internet presentation
 
Presentation internet programming report
Presentation internet programming reportPresentation internet programming report
Presentation internet programming report
 
Magnetic storage devices
Magnetic storage devicesMagnetic storage devices
Magnetic storage devices
 
How internet technology be used to spread scientific awareness among pakistan...
How internet technology be used to spread scientific awareness among pakistan...How internet technology be used to spread scientific awareness among pakistan...
How internet technology be used to spread scientific awareness among pakistan...
 
Math assignment Program
Math assignment ProgramMath assignment Program
Math assignment Program
 
Final of sentences PPT
Final of sentences PPTFinal of sentences PPT
Final of sentences PPT
 
Advantages and disadvantages of LCD
Advantages and disadvantages of LCDAdvantages and disadvantages of LCD
Advantages and disadvantages of LCD
 
A history of windows
A history of windowsA history of windows
A history of windows
 
Lcd
LcdLcd
Lcd
 
Bluetooth 27 01-12 PPT
Bluetooth 27 01-12 PPTBluetooth 27 01-12 PPT
Bluetooth 27 01-12 PPT
 
Bluetooth PPT Report
Bluetooth PPT ReportBluetooth PPT Report
Bluetooth PPT Report
 
Computing assignment 02 ms access (bilal maqbool 10) se-i
Computing assignment 02   ms access (bilal maqbool 10)          se-iComputing assignment 02   ms access (bilal maqbool 10)          se-i
Computing assignment 02 ms access (bilal maqbool 10) se-i
 
Bilal maqbool assignment no.01 computing
Bilal maqbool assignment no.01 computingBilal maqbool assignment no.01 computing
Bilal maqbool assignment no.01 computing
 

Dernier

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Dernier (20)

General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 

Dld lecture module 02

  • 1. 3/28/2012 1 Digital Logic & Design Dr. Sajjad Ahmed Nadeem Department of Computer Science & IT University of Azad Jammu & Kashmir Muzaffarabad Module 02_01 Complements. The (r-1)’s Complement. The r’s Complement. Subtraction with Complements.
  • 2. 3/28/2012 2 Complements (1) Used in digital computers for ◦ simplifying the subtraction operation ◦ logical manipulations. There are two types of complements for each base-r system: 1. The (r – 1)’s Complement (Diminished radix complement). 2. The r’s Complement (Radix complement). For Decimal numbers we have 9’s and 10’s complement For Binary numbers we have 1’s and 2’s complement Complements (2) Complements of numbers with fractions 1. Remove the radix point 2. Obtain the complement 3. Return the radix point to its position
  • 3. 3/28/2012 3 The (r – 1)’s Complement (1) Let X be a positive number in base r with n digits, the (r – 1)’s complement of X is defined as (rⁿ - 1) – X For r=10, it is called 9’s complement and is given by (10ⁿ - 1) – X For r=2, it is called 1’s complement and is given by (2ⁿ - 1) – X The (r – 1)’s Complement (2) The 9’s complement of (52520)10 is {(105 – 1) – 52520} = 99999 – 52520 = 47479. The 9’s complement of (0.3267)10 is {(104 – 1) – 3267} = 9999 – 3267 = 6732. (Answer is 0.6732.) The 9’s complement of (25.639)10 is (105– 1– 25639) = 99999 – 25639 = 74360. (Answer is 74.360.)
  • 4. 3/28/2012 4 The (r – 1)’s Complement (3) The 1’s complement of (101100)2 is (26 – 1) 10 – (101100)2 = (111111 – 101100)2 = 010011. The 1’s complement of (0.0110)2 is (24 – 1)10 – (0110)2 = (1111 – 0110)2 = 1001. (Answer is 0.1001) The 1’s complement of (100.0110)2 is (27 – 1)10 – (1000110)2 = (1111111 – 1000110)2 = 0111001. (Answer is 011.1001) The (r – 1)’s Complement (4) The 9’s complement of a decimal number is formed simply by subtracting every digit from 9. The 1’s complement of a binary number is simpler to form: the 1’s are changed to 0’s and 0’s to 1’s.
  • 5. 3/28/2012 5 The r’s Complement (1) Let X be a positive number in base r with n digits, the r’s complement of X is defined as rⁿ – X for X ≠ 0 0 for X = 0 For r=10, it is called 10’s complement and is given by 10ⁿ – X = (10ⁿ – 1) – X + 1 For r=2, it is called 2’s complement and is given by 2ⁿ – X = (2ⁿ – 1) – X + 1 The r’s Complement (1) The 10’s complement of (52520)10 is (105 – 1) – 52520 + 1 = 47480. (The number of digits in the number is n=5.) The 10’s complement of (0.3267)10 is (104 – 1) – 3267 + 1 = 6733 (Answer is 0.6733) The 10’s complement of (25.639)10 is (105 – 1) – 25639 + 1= 74361 (Answer is 74.361)
  • 6. 3/28/2012 6 The r’s Complement (2) The 2’s Complement of (101100)2 is {(26 – 1)10 – (101100)2 }+ 1 = (111111 – 101100)+1 = 010100. The 2’s Complement of (0.0110)2 is {(24 – 1)10 – (0110)2 }+ 1 = 1010. (Answer is 0.1010) The r’s Complement (3) 10’s complement can be formed by ◦ leaving all least significant zeros unchanged and ◦ then subtracting the first non-zero least significant digit from 10, and ◦ then subtracting all other higher significant digits from 9. The 2’s Complement can be formed by ◦ leaving all least significant zeros and first non zero digit unchanged, and ◦ then replacing 1’s by 0’s and 0’s by 1’s in all other higher significant digits.
  • 7. 3/28/2012 7 Complement of Complement The complement of complement restores the number to its original value. The r’s complement of N is rⁿ - N. Therefore, the complement of (rⁿ - N) is rⁿ - (rⁿ - N) = N Subtraction with r’s compliment (1) The subtraction of two positive numbers (M – N), both of base r, may be done as follows. 1. Add the minuend M to the r’s complement of subtrahend N. M – N =M+ r’s complement (N) 2. Inspect the result obtained in step 1 for an end carry: (a) If an end carry occurs discard it. (b) If an end carry does not occur, take the r’s complement of the number obtained in step 1, and place a negative sign in front.
  • 8. 3/28/2012 8 Subtraction with r’s compliment (2) Using 10’s complement,subtract 72532 – 3250. M = 72532 , N = 03250. 10’s complement of subtrahend N = 96750. Step 1: 72532 + 96750 End Carry 1 69282 Step 2, discard carry. Answer = 69282. Subtraction with r’s compliment (3) Subtract: (3250 – 72532)10 M = 03250,N = 72532. 10’s complement of N = 27468. Step 1: 03250 + 27468 30718 (No End Carry) Step 2:Answer = - (10’s complement of 30718) Answer = - 69282
  • 9. 3/28/2012 9 Subtraction with r’s compliment (4) Using 2’s complement, subtract 1010100 – 1000100. M = 1010100,N = 1000100. 2’s complement of N = 0111100 Step 1: 1010100 + 0111100 End Carry 1 0010000 Step 2: Discard Carry. Answer = 0010000 Subtraction with r’s compliment (5) Using 2’s complement, subtract 1000100 – 1010100. M = 1000100,N = 1010100. 2’s complement of N = 0101100 Step 1: 1000100 + 0101100 No Carry 1110000 Step 2:Answer = - (2’s complement of 1110000) Answer = - 0010000
  • 10. 3/28/2012 10 Subtraction with (r – 1)’s compliment (1) The procedure for subtraction with the (r – 1)’s complement is exactly the same as the one used with r’s compliment except for one variation, called “end-round carry”. The subtraction of two positive numbers (M – N), both of base r, may be done as follows. 1. Add the minuend M to the (r – 1)’s complement of the subtrahend N. M – N =M+ (r – 1)’s complement (N) 2. Inspect the result obtained in step 1 for an End carry. (a) If an end carry occurs, add 1 to the least significant digit ( end-around carry). (b) If an end carry does not occur, take the (r – 1)’s complement of the number obtained in step 1 and place a negative sign in front. Using 9’s complement, subtract 72532 – 3250. M = 72532 , N = 03250. 9’s complement of subtrahend N = 96749. Step 1: 72532 + 96749 End-around Carry 1 69281 Step 2,add end around carry. + 1 Answer = 69282 Subtraction with (r – 1)’s compliment (2)
  • 11. 3/28/2012 11 Subtract: (3250 – 72532)10 M = 03250,N = 72532. 9’s complement of N = 27467. Step 1: 03250 + 27467 30717 (No End Carry) Step 2:Answer = - (9’s complement of 30717) Answer = - 69282 Subtraction with (r – 1)’s compliment (3) Using 1’s complement, subtract 1010100 – 1000100. M = 1010100,N = 1000100. 1’s complement of N = 0111011 Step 1: 1010100 + 0111011 End Carry 1 0001111 Step 2 + 1 Answer = 0010000 Subtraction with (r – 1)’s compliment (4)
  • 12. 3/28/2012 12 Using 1’s complement, subtract 1000100 – 1010100. M = 1000100,N = 1010100. 1’s complement of N = 0101011 Step 1: 1000100 + 0101011 No Carry 1101111 Step 2:Answer = - (1’s complement of 1101111) Answer = - 10000 Subtraction with (r – 1)’s compliment (5) Signed Binary Numbers (1) We have one way to represent a positive number (say +9) Three ways to represent a negative numbers (say -9) Sign Bit ◦ Signed-magnitude representation 1 0001001 ◦ Signed-1’s complement representation 1 1110110 ◦ Signed-2’s complement representation 1 1110111
  • 13. 3/28/2012 13 Signed Binary Numbers (2) Signed Binary Numbers-Addition Addition of two numbers in signed magnitude system follow the same rules of ordinary arithmatic. The addition of two signed binary numbers ◦ Use binary representation of the numbers and add them ◦ In case of negative number, add the 2’s complement of the negative number to the positive number alongwith sign bits ◦ Add the 2’s complement of the negative numbers ◦ A carry out of the sign bit position is discarded ◦ If the sum obtained is in negative it is automatically in 2’s complement form.
  • 14. 3/28/2012 14 Signed Binary Numbers-Subtraction Take the 2’s complement of the subtrahed (including the sign bit) Add the obtained 2’s complement to the minuend (including the sign bit). A carry out of sign bit is discarded Assignment r’s complement for octal & hexadecimal (r-1)’s complement for octal & hexadecimal Comparison between 1’s and 2’s Complement.