SlideShare a Scribd company logo
1 of 13
1’s and 2’s Complements
1
2
Complements are used in digital computers in order to simply the subtraction operation and for the logical
manipulations.
For the Binary number (base-2) system, there are two types of complements: 1’s complement and 2’s
complement.
1’s Complement of a Binary Number
There is a simple algorithm to convert a binary number into 1’s complement. To get 1’s complement of a
binary number, simply invert the given number. 1. 101010 --010101
2’s Complement of a Binary Number
There is a simple algorithm to convert a binary number into 2’s complement. To get 2’s complement of a
binary number, simply invert the given number and add 1 to the least significant bit (LSB) of given result.
1. 1110001110 ->0001110001 1’s comp
1 ->
0001110010
3
4
Subtractions by 1’s Complement:
The algorithm to subtract two binary number using 1’s complement is explained as following below:
•Take 1’s complement of the subtrahend
•Add with minuend
•If the result of above addition has carry bit 1, then add it to the least significant bit (LSB) of given result
•If there is no carry bit 1, then take 1’s complement of the result which will be negative
Note that subtrahend is number that to be subtracted from the another number, i.e., minuend.
Example (Case-1: When Carry bit 1):
Evaluate 10101 – 00101 00101 from 10101
According to above algorithm,
take 1’s complement of subtrahend 00101, which will be 11010, then add both of these.
So, 10101 + 11010 =1 01111 .
Since, there is carry bit 1, so add this to the LSB of given result,
i.e., 01111+1=10000 which is the answer.
5
Example (Case-2: When no Carry bit):
Evaluate 11001 - 11110
According to above algorithm,
take 1’s complement of subtrahend 11110, which will be 00001.
Then add both of these, So, 11001 + 00001 =11010 .
Since there is no carry bit 1, so take 1’s complement of above result,
which will be 11010, and this is negative number, i.e, 00101, which is the answer.
6
Additions by 1’s Complement:
There are difference scenario for addition of two binary numbers using 1’s complement. These are
explained as following below.
Case-1: Addition of positive and negative number when positive number has greater magnitude:
When positive number has greater magnitude, then take simply 1’s complement of negative number and
then add with the positive number, if there is any end-around carry of the sum then add the carry with
the least significant bit (LSB).
Example: Add 1110 and -1101. 1110 = E or 14 and 1101 = D or 13
So, take 1’s complement of 1101, which will be 0010, then add with given number. So, 1110+0010=1
0000 , then add this carry bit to the LSB, 0000+1=0001 , which is the answer.
7
Additions by 1’s Complement:
There are difference scenario for addition of two binary numbers using 1’s complement. These are
explained as following below.
Case-2: Addition of positive and negative number when negative number has greater magnitude:
When the negative number has greater magnitude, then take 1’s complement of negative number
and add with given positive number. Since there will not be any end-around carry bit, so take 1’s
complement of the result and this result will be negative.
Example: Add 1010 and -1100 in five-bit registers. 10 +(– 12) = -2
Note that there are five-bit registers, so these new numbers will be 01010 and -01100.
Now take 1’s complement of 01100 which will be 10011 and add 01010+10011=11101 .
Then take 1’s complement of this result, which will be 00010 and this will be negative number, i.e., -
00010, which is the answer.
8
Additions by 1’s Complement:
There are difference scenario for addition of two binary numbers using 1’s complement. These are
explained as following below.
Case-3: Addition of two negative numbers:
You need to take 1’s complement for both numbers, then add these 1’s complement of numbers.
Since there will always be end-around carry bit, so add this again to the LSB of result. Now, take 1’s
complement also of previous result, so this will be negative number.
Alternatively, you can add both negative number directly, and get this result which will be negative
only.
Example: add -1010 and -0101 in five bit-register. - 01010 = -10 and – 00101 = -5 = (-10)=(-5) = -15
These five bit numbers are -01010 and -00101.
Add complements of these numbers, 10101+11010 =1 01111 . Since, there is a carry bit 1, so add this
to the LSB of result, i.e., 01111+1=10000 . Now take the 1’s complement of this result, which will be
01111 and this number is negative, i.e, -01111, which is answer.
9
Subtraction by 2’s Complement
The operation is carried out by means of the following steps:
(i) At first, 2’s complement of the subtrahend is found.
(ii) Then it is added to the minuend.
(iii) If the final carry over of the sum is 1, it is dropped and the result is positive.
(iv) If there is no carry over, the two’s complement of the sum will be the result and it is negative.
(i) 110110 - 010110
Solution:
The numbers of bits in the subtrahend is 5 while that of minuend is 6. We make the
number of bits in the subtrahend equal to that of minuend by taking a `0’ in the sixth
place of the subtrahend.
Now, 2’s complement of 010110 is (101001 + 1) i.e.101010. Adding this with the
minuend.
1 1 0 1 1 0 Minuend
1 0 1 0 1 0 2’s complement of subtrahend
Carry over 1 1 0 0 0 0 0 Result of addition
After dropping the carry over we get the result of subtraction to be 100000.
10
(ii) 10110 – 11010
Solution:
2’s complement of 11010 is (00101 + 1) i.e. 00110. Hence
Minued - 1 0 1 1 0
2’s complement of subtrahend -0 0 1 1 0
Result of addition - 1 1 1 0 0
As there is no carry over, the result of subtraction is
negative and is obtained by writing the 2’s complement
of 11100 i.e.(00011 + 1) or Hence the difference is – 100.
00100.
(iii) 1010.11 – 1001.01
Solution:
2’s complement of 1001.01 is 0110.11. Hence
Minued - 1 0 1 0 . 1 1
2’s complement of subtrahend - 0 1 1 0 . 1
1
Carry over 1 0 0 0 1 . 1 0
After dropping the carry over we get the result of
subtraction as 1.10
11
Addition by 2’s Complement
When negative numbers are expressed in binary addition using 2’s complement the addition of binary numbers
becomes easier. This operation is almost similar to that in 1’s complement system and is explained with examples
given below
A. Addition of a positive number and a negative number.
We consider the following cases.
Case I: When the positive number has a greater magnitude
In this case the carry which will be generated is discarded and the final result is the result of addition.
The following examples will illustrate this method in binary addition using 2’s complement:
In a 5-bit register find the sum of the following by using 2’s complement:
(i) 1011 and -0101 01011 & -00101 , 11010 +1 = 11011
Solution:
+ 1 0 1 1 ⇒ 0 1 0 1 1
- 0 1 0 1 ⇒ 1 1 0 1 1 (2’s complement)
(Carry 1 discarded) 0 0 1 1 0
Hence the sum is + 00110.
12
Addition by 2’s Complement
Case II: When the negative number is greater.
When the negative numbers is greater no carry will be generated in the sign bit. The result of addition will be
negative and the final result is obtained by taking 2’s complement of the magnitude bits of the result.
The following examples will illustrate this method in binary addition using 2’s complement:
In a 5-bit register find the sum of the following by using 2’s complement:
(i) + 0 0 1 1 and - 0 1 0 1
Solution:
+ 0 0 0 1 1 ⇒ 0 0 0 1 1
- 0 0 1 0 1 ⇒ 1 1 0 1 1 (2’s complement) 11011
1 1 1 1 0 00001+1 =
00010
2’s complement of 1110 is (0001 + 0001) or 0010.
Hence the required sum is - 00010.
13
Addition by 2’s Complement
Case III: When the numbers are negative.
When two negative numbers are added a carry will be generated from the sign bit which will be discarded. 2’s
complement of the magnitude bits of the operation will be the final sum.
The following examples will illustrate this method in binary addition using 2’s complement:
In a 5-bit register find the sum of the following by using 2’s complement:
(i) – 00011 and – 00101
Solution:
- 0 0 0 1 1 ⇒ 1 1 1 0 1 (2’s complement) 11100+1 = 11101
- 0 0 1 0 1 ⇒ 1 1 0 1 1 (2’s complement) 11010+1 = 11011
(Carry 1 discarded) 1 1 1 0 0 0
2’s complement of 11000 is (00111 +1) or 01000.
Hence the required sum is – 01000.

More Related Content

What's hot

Fixed point and floating-point numbers
Fixed point and  floating-point numbersFixed point and  floating-point numbers
Fixed point and floating-point numbersMOHAN MOHAN
 
Decoder Full Presentation
Decoder Full Presentation Decoder Full Presentation
Decoder Full Presentation Adeel Rasheed
 
IEEE floating point representation
 IEEE floating point representation IEEE floating point representation
IEEE floating point representationMaskurAlShalSabil
 
Decimal to binary number
Decimal to binary numberDecimal to binary number
Decimal to binary numberguestd8696a
 
Floating point presentation
Floating point presentationFloating point presentation
Floating point presentationSnehalataAgasti
 
Number system in Digital Electronics
Number system in Digital ElectronicsNumber system in Digital Electronics
Number system in Digital ElectronicsJanki Shah
 
Adder & subtractor (Half adder, Full adder, Half subtractor, Full subtractor)
Adder & subtractor (Half adder, Full adder, Half subtractor, Full subtractor)Adder & subtractor (Half adder, Full adder, Half subtractor, Full subtractor)
Adder & subtractor (Half adder, Full adder, Half subtractor, Full subtractor)ISMT College
 
EC Binary Substraction using 1's Complement,2's Complement
EC Binary Substraction using 1's Complement,2's ComplementEC Binary Substraction using 1's Complement,2's Complement
EC Binary Substraction using 1's Complement,2's ComplementAmberSinghal1
 
Half adder & full adder
Half adder & full adderHalf adder & full adder
Half adder & full adderGaditek
 

What's hot (20)

BINARY SUBTRACTION
BINARY SUBTRACTIONBINARY SUBTRACTION
BINARY SUBTRACTION
 
Binary Arithmetic
Binary ArithmeticBinary Arithmetic
Binary Arithmetic
 
Fixed point and floating-point numbers
Fixed point and  floating-point numbersFixed point and  floating-point numbers
Fixed point and floating-point numbers
 
Binary arithmetic
Binary arithmeticBinary arithmetic
Binary arithmetic
 
Complements
ComplementsComplements
Complements
 
Decoder Full Presentation
Decoder Full Presentation Decoder Full Presentation
Decoder Full Presentation
 
IEEE floating point representation
 IEEE floating point representation IEEE floating point representation
IEEE floating point representation
 
Binary Arithmetic Operations
Binary Arithmetic OperationsBinary Arithmetic Operations
Binary Arithmetic Operations
 
What is Gray Code?
What is Gray Code? What is Gray Code?
What is Gray Code?
 
Digital electronics
Digital electronicsDigital electronics
Digital electronics
 
Decimal to binary number
Decimal to binary numberDecimal to binary number
Decimal to binary number
 
Floating point presentation
Floating point presentationFloating point presentation
Floating point presentation
 
Number system in Digital Electronics
Number system in Digital ElectronicsNumber system in Digital Electronics
Number system in Digital Electronics
 
Logic gates
Logic gatesLogic gates
Logic gates
 
Adder & subtractor (Half adder, Full adder, Half subtractor, Full subtractor)
Adder & subtractor (Half adder, Full adder, Half subtractor, Full subtractor)Adder & subtractor (Half adder, Full adder, Half subtractor, Full subtractor)
Adder & subtractor (Half adder, Full adder, Half subtractor, Full subtractor)
 
EC Binary Substraction using 1's Complement,2's Complement
EC Binary Substraction using 1's Complement,2's ComplementEC Binary Substraction using 1's Complement,2's Complement
EC Binary Substraction using 1's Complement,2's Complement
 
Half adder & full adder
Half adder & full adderHalf adder & full adder
Half adder & full adder
 
Two’s complement
Two’s complementTwo’s complement
Two’s complement
 
Digital Logic circuit
Digital Logic circuitDigital Logic circuit
Digital Logic circuit
 
Boolean Algebra
Boolean AlgebraBoolean Algebra
Boolean Algebra
 

Similar to 1’s and 2’s complements

B sc3 unit 2 number system
B sc3  unit 2 number systemB sc3  unit 2 number system
B sc3 unit 2 number systemMahiboobAliMulla
 
FYBSC IT Digital Electronics Unit I Chapter II Number System and Binary Arith...
FYBSC IT Digital Electronics Unit I Chapter II Number System and Binary Arith...FYBSC IT Digital Electronics Unit I Chapter II Number System and Binary Arith...
FYBSC IT Digital Electronics Unit I Chapter II Number System and Binary Arith...Arti Parab Academics
 
L3 ARITHMETIC OPERATIONS.pptx
L3 ARITHMETIC OPERATIONS.pptxL3 ARITHMETIC OPERATIONS.pptx
L3 ARITHMETIC OPERATIONS.pptxHarish257692
 
1's and 2's complement.pptx
1's and 2's complement.pptx1's and 2's complement.pptx
1's and 2's complement.pptxHKShab
 
558196807-1-s-and-2-s-complement-Lecture-3.ppt
558196807-1-s-and-2-s-complement-Lecture-3.ppt558196807-1-s-and-2-s-complement-Lecture-3.ppt
558196807-1-s-and-2-s-complement-Lecture-3.pptEMMANUEL932242
 
Arithmetic logic units
Arithmetic logic unitsArithmetic logic units
Arithmetic logic unitsowaisahmad125
 
Binaty Arithmetic and Binary coding schemes
Binaty Arithmetic and Binary coding schemesBinaty Arithmetic and Binary coding schemes
Binaty Arithmetic and Binary coding schemesDr. Anita Goel
 
Number system
Number systemNumber system
Number systemaviban
 
1sand2scomplement r004
1sand2scomplement  r0041sand2scomplement  r004
1sand2scomplement r004arunachalamr16
 
Number system arithmetic
Number system arithmetic Number system arithmetic
Number system arithmetic renatus katundu
 
Chapter 2 Data Representation on CPU (part 1)
Chapter 2 Data Representation on CPU (part 1)Chapter 2 Data Representation on CPU (part 1)
Chapter 2 Data Representation on CPU (part 1)Frankie Jones
 
Integer Representation
Integer RepresentationInteger Representation
Integer Representationgavhays
 

Similar to 1’s and 2’s complements (20)

Arithmetic Logic
Arithmetic LogicArithmetic Logic
Arithmetic Logic
 
B sc3 unit 2 number system
B sc3  unit 2 number systemB sc3  unit 2 number system
B sc3 unit 2 number system
 
B sc ii sem unit 2(a) ns
B sc ii sem  unit 2(a) nsB sc ii sem  unit 2(a) ns
B sc ii sem unit 2(a) ns
 
FYBSC IT Digital Electronics Unit I Chapter II Number System and Binary Arith...
FYBSC IT Digital Electronics Unit I Chapter II Number System and Binary Arith...FYBSC IT Digital Electronics Unit I Chapter II Number System and Binary Arith...
FYBSC IT Digital Electronics Unit I Chapter II Number System and Binary Arith...
 
L3 ARITHMETIC OPERATIONS.pptx
L3 ARITHMETIC OPERATIONS.pptxL3 ARITHMETIC OPERATIONS.pptx
L3 ARITHMETIC OPERATIONS.pptx
 
1's and 2's complement.pptx
1's and 2's complement.pptx1's and 2's complement.pptx
1's and 2's complement.pptx
 
558196807-1-s-and-2-s-complement-Lecture-3.ppt
558196807-1-s-and-2-s-complement-Lecture-3.ppt558196807-1-s-and-2-s-complement-Lecture-3.ppt
558196807-1-s-and-2-s-complement-Lecture-3.ppt
 
Arithmetic logic units
Arithmetic logic unitsArithmetic logic units
Arithmetic logic units
 
unit-2_DL.pdf
unit-2_DL.pdfunit-2_DL.pdf
unit-2_DL.pdf
 
1sand2scomplement.pdf
1sand2scomplement.pdf1sand2scomplement.pdf
1sand2scomplement.pdf
 
Binaty Arithmetic and Binary coding schemes
Binaty Arithmetic and Binary coding schemesBinaty Arithmetic and Binary coding schemes
Binaty Arithmetic and Binary coding schemes
 
Number system
Number systemNumber system
Number system
 
1sand2scomplement r004
1sand2scomplement  r0041sand2scomplement  r004
1sand2scomplement r004
 
Number system arithmetic
Number system arithmetic Number system arithmetic
Number system arithmetic
 
ch2.pdf
ch2.pdfch2.pdf
ch2.pdf
 
Chapter 2 Data Representation on CPU (part 1)
Chapter 2 Data Representation on CPU (part 1)Chapter 2 Data Representation on CPU (part 1)
Chapter 2 Data Representation on CPU (part 1)
 
Digital computer fundamentals
Digital computer fundamentalsDigital computer fundamentals
Digital computer fundamentals
 
The number system
The number systemThe number system
The number system
 
Representation of Negative Numbers
Representation of Negative NumbersRepresentation of Negative Numbers
Representation of Negative Numbers
 
Integer Representation
Integer RepresentationInteger Representation
Integer Representation
 

More from arunachalamr16

08 logic simplification
08 logic simplification08 logic simplification
08 logic simplificationarunachalamr16
 
Boolean variables r010
Boolean variables   r010Boolean variables   r010
Boolean variables r010arunachalamr16
 
Central processing unit and stack organization r013
Central processing unit and stack organization   r013Central processing unit and stack organization   r013
Central processing unit and stack organization r013arunachalamr16
 
Combinational circuits r011
Combinational circuits   r011Combinational circuits   r011
Combinational circuits r011arunachalamr16
 
Binary coded decimal r004
Binary coded decimal   r004Binary coded decimal   r004
Binary coded decimal r004arunachalamr16
 
Digital fundamendals r001a
Digital fundamendals r001aDigital fundamendals r001a
Digital fundamendals r001aarunachalamr16
 
18 pc09 1.2_ digital logic gates _ boolean algebra_basic theorems
18 pc09 1.2_ digital logic gates _ boolean algebra_basic theorems18 pc09 1.2_ digital logic gates _ boolean algebra_basic theorems
18 pc09 1.2_ digital logic gates _ boolean algebra_basic theoremsarunachalamr16
 
Error detection and correction codes r006
Error detection and correction codes   r006Error detection and correction codes   r006
Error detection and correction codes r006arunachalamr16
 

More from arunachalamr16 (19)

Pipeline r014
Pipeline   r014Pipeline   r014
Pipeline r014
 
Registers r011
Registers   r011Registers   r011
Registers r011
 
08 logic simplification
08 logic simplification08 logic simplification
08 logic simplification
 
Boolean algebra r009
Boolean algebra   r009Boolean algebra   r009
Boolean algebra r009
 
Boolean variables r010
Boolean variables   r010Boolean variables   r010
Boolean variables r010
 
Central processing unit and stack organization r013
Central processing unit and stack organization   r013Central processing unit and stack organization   r013
Central processing unit and stack organization r013
 
Combinational circuits r011
Combinational circuits   r011Combinational circuits   r011
Combinational circuits r011
 
Counters r012
Counters  r012Counters  r012
Counters r012
 
Flipflop r012
Flipflop   r012Flipflop   r012
Flipflop r012
 
Code conversion r006
Code conversion r006Code conversion r006
Code conversion r006
 
Binary coded decimal r004
Binary coded decimal   r004Binary coded decimal   r004
Binary coded decimal r004
 
Digital fundamendals r001a
Digital fundamendals r001aDigital fundamendals r001a
Digital fundamendals r001a
 
Universal gates r008
Universal gates   r008Universal gates   r008
Universal gates r008
 
Number systems r002
Number systems  r002Number systems  r002
Number systems r002
 
Logic gates r007
Logic gates   r007Logic gates   r007
Logic gates r007
 
18 pc09 1.2_ digital logic gates _ boolean algebra_basic theorems
18 pc09 1.2_ digital logic gates _ boolean algebra_basic theorems18 pc09 1.2_ digital logic gates _ boolean algebra_basic theorems
18 pc09 1.2_ digital logic gates _ boolean algebra_basic theorems
 
Error detection and correction codes r006
Error detection and correction codes   r006Error detection and correction codes   r006
Error detection and correction codes r006
 
Codes r005
Codes  r005Codes  r005
Codes r005
 
Pill camera
Pill cameraPill camera
Pill camera
 

Recently uploaded

CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 

Recently uploaded (20)

CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 

1’s and 2’s complements

  • 1. 1’s and 2’s Complements 1
  • 2. 2 Complements are used in digital computers in order to simply the subtraction operation and for the logical manipulations. For the Binary number (base-2) system, there are two types of complements: 1’s complement and 2’s complement. 1’s Complement of a Binary Number There is a simple algorithm to convert a binary number into 1’s complement. To get 1’s complement of a binary number, simply invert the given number. 1. 101010 --010101 2’s Complement of a Binary Number There is a simple algorithm to convert a binary number into 2’s complement. To get 2’s complement of a binary number, simply invert the given number and add 1 to the least significant bit (LSB) of given result. 1. 1110001110 ->0001110001 1’s comp 1 -> 0001110010
  • 3. 3
  • 4. 4 Subtractions by 1’s Complement: The algorithm to subtract two binary number using 1’s complement is explained as following below: •Take 1’s complement of the subtrahend •Add with minuend •If the result of above addition has carry bit 1, then add it to the least significant bit (LSB) of given result •If there is no carry bit 1, then take 1’s complement of the result which will be negative Note that subtrahend is number that to be subtracted from the another number, i.e., minuend. Example (Case-1: When Carry bit 1): Evaluate 10101 – 00101 00101 from 10101 According to above algorithm, take 1’s complement of subtrahend 00101, which will be 11010, then add both of these. So, 10101 + 11010 =1 01111 . Since, there is carry bit 1, so add this to the LSB of given result, i.e., 01111+1=10000 which is the answer.
  • 5. 5 Example (Case-2: When no Carry bit): Evaluate 11001 - 11110 According to above algorithm, take 1’s complement of subtrahend 11110, which will be 00001. Then add both of these, So, 11001 + 00001 =11010 . Since there is no carry bit 1, so take 1’s complement of above result, which will be 11010, and this is negative number, i.e, 00101, which is the answer.
  • 6. 6 Additions by 1’s Complement: There are difference scenario for addition of two binary numbers using 1’s complement. These are explained as following below. Case-1: Addition of positive and negative number when positive number has greater magnitude: When positive number has greater magnitude, then take simply 1’s complement of negative number and then add with the positive number, if there is any end-around carry of the sum then add the carry with the least significant bit (LSB). Example: Add 1110 and -1101. 1110 = E or 14 and 1101 = D or 13 So, take 1’s complement of 1101, which will be 0010, then add with given number. So, 1110+0010=1 0000 , then add this carry bit to the LSB, 0000+1=0001 , which is the answer.
  • 7. 7 Additions by 1’s Complement: There are difference scenario for addition of two binary numbers using 1’s complement. These are explained as following below. Case-2: Addition of positive and negative number when negative number has greater magnitude: When the negative number has greater magnitude, then take 1’s complement of negative number and add with given positive number. Since there will not be any end-around carry bit, so take 1’s complement of the result and this result will be negative. Example: Add 1010 and -1100 in five-bit registers. 10 +(– 12) = -2 Note that there are five-bit registers, so these new numbers will be 01010 and -01100. Now take 1’s complement of 01100 which will be 10011 and add 01010+10011=11101 . Then take 1’s complement of this result, which will be 00010 and this will be negative number, i.e., - 00010, which is the answer.
  • 8. 8 Additions by 1’s Complement: There are difference scenario for addition of two binary numbers using 1’s complement. These are explained as following below. Case-3: Addition of two negative numbers: You need to take 1’s complement for both numbers, then add these 1’s complement of numbers. Since there will always be end-around carry bit, so add this again to the LSB of result. Now, take 1’s complement also of previous result, so this will be negative number. Alternatively, you can add both negative number directly, and get this result which will be negative only. Example: add -1010 and -0101 in five bit-register. - 01010 = -10 and – 00101 = -5 = (-10)=(-5) = -15 These five bit numbers are -01010 and -00101. Add complements of these numbers, 10101+11010 =1 01111 . Since, there is a carry bit 1, so add this to the LSB of result, i.e., 01111+1=10000 . Now take the 1’s complement of this result, which will be 01111 and this number is negative, i.e, -01111, which is answer.
  • 9. 9 Subtraction by 2’s Complement The operation is carried out by means of the following steps: (i) At first, 2’s complement of the subtrahend is found. (ii) Then it is added to the minuend. (iii) If the final carry over of the sum is 1, it is dropped and the result is positive. (iv) If there is no carry over, the two’s complement of the sum will be the result and it is negative. (i) 110110 - 010110 Solution: The numbers of bits in the subtrahend is 5 while that of minuend is 6. We make the number of bits in the subtrahend equal to that of minuend by taking a `0’ in the sixth place of the subtrahend. Now, 2’s complement of 010110 is (101001 + 1) i.e.101010. Adding this with the minuend. 1 1 0 1 1 0 Minuend 1 0 1 0 1 0 2’s complement of subtrahend Carry over 1 1 0 0 0 0 0 Result of addition After dropping the carry over we get the result of subtraction to be 100000.
  • 10. 10 (ii) 10110 – 11010 Solution: 2’s complement of 11010 is (00101 + 1) i.e. 00110. Hence Minued - 1 0 1 1 0 2’s complement of subtrahend -0 0 1 1 0 Result of addition - 1 1 1 0 0 As there is no carry over, the result of subtraction is negative and is obtained by writing the 2’s complement of 11100 i.e.(00011 + 1) or Hence the difference is – 100. 00100. (iii) 1010.11 – 1001.01 Solution: 2’s complement of 1001.01 is 0110.11. Hence Minued - 1 0 1 0 . 1 1 2’s complement of subtrahend - 0 1 1 0 . 1 1 Carry over 1 0 0 0 1 . 1 0 After dropping the carry over we get the result of subtraction as 1.10
  • 11. 11 Addition by 2’s Complement When negative numbers are expressed in binary addition using 2’s complement the addition of binary numbers becomes easier. This operation is almost similar to that in 1’s complement system and is explained with examples given below A. Addition of a positive number and a negative number. We consider the following cases. Case I: When the positive number has a greater magnitude In this case the carry which will be generated is discarded and the final result is the result of addition. The following examples will illustrate this method in binary addition using 2’s complement: In a 5-bit register find the sum of the following by using 2’s complement: (i) 1011 and -0101 01011 & -00101 , 11010 +1 = 11011 Solution: + 1 0 1 1 ⇒ 0 1 0 1 1 - 0 1 0 1 ⇒ 1 1 0 1 1 (2’s complement) (Carry 1 discarded) 0 0 1 1 0 Hence the sum is + 00110.
  • 12. 12 Addition by 2’s Complement Case II: When the negative number is greater. When the negative numbers is greater no carry will be generated in the sign bit. The result of addition will be negative and the final result is obtained by taking 2’s complement of the magnitude bits of the result. The following examples will illustrate this method in binary addition using 2’s complement: In a 5-bit register find the sum of the following by using 2’s complement: (i) + 0 0 1 1 and - 0 1 0 1 Solution: + 0 0 0 1 1 ⇒ 0 0 0 1 1 - 0 0 1 0 1 ⇒ 1 1 0 1 1 (2’s complement) 11011 1 1 1 1 0 00001+1 = 00010 2’s complement of 1110 is (0001 + 0001) or 0010. Hence the required sum is - 00010.
  • 13. 13 Addition by 2’s Complement Case III: When the numbers are negative. When two negative numbers are added a carry will be generated from the sign bit which will be discarded. 2’s complement of the magnitude bits of the operation will be the final sum. The following examples will illustrate this method in binary addition using 2’s complement: In a 5-bit register find the sum of the following by using 2’s complement: (i) – 00011 and – 00101 Solution: - 0 0 0 1 1 ⇒ 1 1 1 0 1 (2’s complement) 11100+1 = 11101 - 0 0 1 0 1 ⇒ 1 1 0 1 1 (2’s complement) 11010+1 = 11011 (Carry 1 discarded) 1 1 1 0 0 0 2’s complement of 11000 is (00111 +1) or 01000. Hence the required sum is – 01000.