SlideShare a Scribd company logo
One’s and Two’s Complement
Numbers and Arithmetic
Operations
1
Digital electronics
13IDP14
2
OutlineOutline
 Number of binary digits (bits) used in
computers for arithmetic operations
 Positive and negative number representation
using bits
 1’s complement and 2’s complement
 Arithmetic operations in 2’s complement
 Carry and overflow concepts
 See module 2a notes for more examples
Bits Used in Computers for
Numbers and Implications
 4, 8, 16, 32, 64
 Using 4 bits we can only represent 24
= 16
numbers -8, -7, -6, -5, …-1, 0, 1, … 7
 Using 8 bits we can only represent 28
= 256
numbers -128, -127, …-1, 0, 1, … 127
 Since we can represent only a fixed number of
positive and negative numbers, we may get
wrong results when we compute arithmetic
operations
 We must determine when the results are
wrong
One’s and Two’s Complement
0111 0110 0101 0100 0011 0010 0001 0000 1111 1110 1101 1100 1011 1010 1001 1000
+7 +6 +5 +4 +3 +2 +1 +0 -0 -1 -2 -3 -4 -5 -6 -7
Cryptography -Part -I 4
0111 0110 0101 0100 0011 0010 0001 0000 1111 1110 1101 1100 1011 1010 1001 1000
+7 +6 +5 +4 +3 +2 +1 +0 -1 -2 -3 -4 -5 -6 -7 -8
One’s Complement
Two’s Complement
Two’s Complement Number
Representation and Value (1)
 MSB represents negative number with a
value.
 Example: 8-bit number say
 1101 0011
 Value in decimal
 = -1*27
+ 1*26
+ 0*25
+ 1*24
+ 0*23
+0*22
+ 1*21
+ 1
 =-128 +64+0+16+0+0+2+1
 =-128+83
 =-45
Cryptography -Part -I 5
Two’s Complement Number
Representation and Value (2)
 Example: 1111 1111
 Decimal Value
 = -1*27
+ 1*26
+ 1*25
+ 1*24
+ 1*23
+1*22
+ 1*21
+ 1
 = -128+64+32+16+8+4+2+1 =-128+127 = -1
 Example: 1000 0000 Value = -128
 Example: 0111 1111 Value = 127
Cryptography -Part -I 6
Finding a Negative of a number
 Assume 1’s complement
 Number 8-bit: 0000 1111; value =15
 Given 15 determine -15
 Change all 0 to 1 and 1 to zero
 Result: 1111 0000 = -127+64+32+16 =-127+112 = -15
 Assume 2’s complement
 Number 8-bit: 0000 1111; value =15
 Given 15 determine -15
 Change all 0 to 1 and 1 to zero then add 1
 Result: 1111 0001 = -128+64+32+16+1 =-128+113 = -15
7
Arithmetic Operations in Two’s
Complement (1)
 Example:Find 7 – 5 assuming 4-bit numbers
7 = 0111 ; -5 =1011 in 2’s complement
0111
1011
-----
10010
Carry in MSB 1, Carry out in MSB 1
Result ok value 2
Arithmetic Operations in Two’s
Complement (2)
 Example:Find 7 + 5 assuming 4-bit numbers
7 = 0111 ; 5 =0101 in 2’s complement
0111
0101
-----
1100
Carry in MSB 1, Carry out in MSB 0
Result wrong; value -4. We can not represent
real value 12. This is overflow.
9
Arithmetic Operations in Two’s
Complement (2)
 Example:Find 7 + 5 assuming 4-bit numbers
7 = 0111 ; 5 =0101 in 2’s complement
0111
0101
-----
1100
Carry in MSB 1, Carry out in MSB 0
Result wrong; value -4. We can not represent
real value 12. This is overflow.
9

More Related Content

PPT
1’s and 2’s complements
PPT
2s complement arithmetic
PPTX
Binary codes
PPT
binary arithmetic rules
PPTX
Universal Gates - Aneesa N Ali
PPTX
1's and 2's complement
PPTX
1.1.2 HEXADECIMAL
PDF
Signed Binary Numbers
1’s and 2’s complements
2s complement arithmetic
Binary codes
binary arithmetic rules
Universal Gates - Aneesa N Ali
1's and 2's complement
1.1.2 HEXADECIMAL
Signed Binary Numbers

What's hot (20)

PDF
Binary codes
PPTX
Design half ,full Adder and Subtractor
PPT
Two’s complement
PDF
Logic gate
PPT
KMAP
PPT
Complements
PPTX
Adder & subtractor (Half adder, Full adder, Half subtractor, Full subtractor)
PDF
Slide03 Number System and Operations Part 1
DOCX
2's complement
PPT
Half adder & full adder
PPT
BCD,GRAY and EXCESS 3 codes
PPT
Understanding Flip Flops
PPTX
Fulll Adder
PPTX
Magnitude comparator
PPTX
A floating-point adder (IEEE 754 floating-point.pptx
PPTX
Linear Block Codes
PPTX
Bcd to excess 3 code converter
PPTX
Binary to grey code conversion
PPTX
EC Binary Substraction using 1's Complement,2's Complement
PPTX
12.Representation of signed binary numbers. Binary codes - BCD code, Gray co...
Binary codes
Design half ,full Adder and Subtractor
Two’s complement
Logic gate
KMAP
Complements
Adder & subtractor (Half adder, Full adder, Half subtractor, Full subtractor)
Slide03 Number System and Operations Part 1
2's complement
Half adder & full adder
BCD,GRAY and EXCESS 3 codes
Understanding Flip Flops
Fulll Adder
Magnitude comparator
A floating-point adder (IEEE 754 floating-point.pptx
Linear Block Codes
Bcd to excess 3 code converter
Binary to grey code conversion
EC Binary Substraction using 1's Complement,2's Complement
12.Representation of signed binary numbers. Binary codes - BCD code, Gray co...
Ad

Viewers also liked (20)

PPTX
1s and 2s complement
PDF
Math1003 1.15 - Integers and 2's Complement
PDF
Math1003 - An Intro to Number Systems
PPTX
Introduction number systems and conversion
PPT
Number System
PPTX
Digital logic mohammed salim ch3
PPTX
Digital logic mohammed salim ch2
PPT
Al2ed chapter11
PDF
Ranjak Vaidic Ganit Preview (Marathi Research Book)
PPTX
DLD Intro
PDF
Main Memory
PDF
OS - Thread
PPTX
Assembly language programming intro
PDF
Operating Systems 1 (7/12) - Threads
PPT
Representation of Negative Numbers
PPTX
Analog and digital signal system : digital logic
PPTX
Thread presentation
PPTX
Binary Arithmetic Presentation about Binary Numbers 2015
PPTX
Binary arithmetic
PPT
Ch5: Threads (Operating System)
1s and 2s complement
Math1003 1.15 - Integers and 2's Complement
Math1003 - An Intro to Number Systems
Introduction number systems and conversion
Number System
Digital logic mohammed salim ch3
Digital logic mohammed salim ch2
Al2ed chapter11
Ranjak Vaidic Ganit Preview (Marathi Research Book)
DLD Intro
Main Memory
OS - Thread
Assembly language programming intro
Operating Systems 1 (7/12) - Threads
Representation of Negative Numbers
Analog and digital signal system : digital logic
Thread presentation
Binary Arithmetic Presentation about Binary Numbers 2015
Binary arithmetic
Ch5: Threads (Operating System)
Ad

Similar to Complement (20)

PPT
Twos_Complement_Binary in Information Technology
PPTX
module 1_class_numbers.pptx
PPT
สอนสนอนlec3สอนสนอนlec3สอนสนอนlec3สอนสนอนlec3สอนสนอนlec3
PDF
Digital logic design of 2nd Lecture 2.pdf
PPTX
DEC Unit 1 Full-1.pptx Boolean Algebra and Logic gates
PPTX
L3 ARITHMETIC OPERATIONS.pptx
PDF
Working With Binary Numbers
PPT
Lecture 3
PPT
Mba admission in india
PPT
Number system and codes
PPT
Mba admission in india
PPTX
ARITHMETIC FOR COMPUTERS
PPTX
ALU.pptx kjvjjfjrshfjshfjrhfjershfherjghre
PPT
ch3a-binary-numbers.ppt
PPTX
Computer Architecture
PPTX
Computer Architecture
PDF
Computer Architecture: ARITHMETIC FOR COMPUTERS
PDF
Notes unit 2
PPTX
CA Unit ii
PPT
lec2_BinaryArithmetic.ppt
Twos_Complement_Binary in Information Technology
module 1_class_numbers.pptx
สอนสนอนlec3สอนสนอนlec3สอนสนอนlec3สอนสนอนlec3สอนสนอนlec3
Digital logic design of 2nd Lecture 2.pdf
DEC Unit 1 Full-1.pptx Boolean Algebra and Logic gates
L3 ARITHMETIC OPERATIONS.pptx
Working With Binary Numbers
Lecture 3
Mba admission in india
Number system and codes
Mba admission in india
ARITHMETIC FOR COMPUTERS
ALU.pptx kjvjjfjrshfjshfjrhfjershfherjghre
ch3a-binary-numbers.ppt
Computer Architecture
Computer Architecture
Computer Architecture: ARITHMETIC FOR COMPUTERS
Notes unit 2
CA Unit ii
lec2_BinaryArithmetic.ppt

Recently uploaded (20)

PDF
Sports Quiz easy sports quiz sports quiz
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
RMMM.pdf make it easy to upload and study
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Cell Structure & Organelles in detailed.
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Insiders guide to clinical Medicine.pdf
Sports Quiz easy sports quiz sports quiz
Renaissance Architecture: A Journey from Faith to Humanism
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Microbial disease of the cardiovascular and lymphatic systems
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Pharma ospi slides which help in ospi learning
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
human mycosis Human fungal infections are called human mycosis..pptx
FourierSeries-QuestionsWithAnswers(Part-A).pdf
RMMM.pdf make it easy to upload and study
Microbial diseases, their pathogenesis and prophylaxis
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Final Presentation General Medicine 03-08-2024.pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Cell Structure & Organelles in detailed.
PPH.pptx obstetrics and gynecology in nursing
Anesthesia in Laparoscopic Surgery in India
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Insiders guide to clinical Medicine.pdf

Complement

  • 1. One’s and Two’s Complement Numbers and Arithmetic Operations 1 Digital electronics 13IDP14
  • 2. 2 OutlineOutline  Number of binary digits (bits) used in computers for arithmetic operations  Positive and negative number representation using bits  1’s complement and 2’s complement  Arithmetic operations in 2’s complement  Carry and overflow concepts  See module 2a notes for more examples
  • 3. Bits Used in Computers for Numbers and Implications  4, 8, 16, 32, 64  Using 4 bits we can only represent 24 = 16 numbers -8, -7, -6, -5, …-1, 0, 1, … 7  Using 8 bits we can only represent 28 = 256 numbers -128, -127, …-1, 0, 1, … 127  Since we can represent only a fixed number of positive and negative numbers, we may get wrong results when we compute arithmetic operations  We must determine when the results are wrong
  • 4. One’s and Two’s Complement 0111 0110 0101 0100 0011 0010 0001 0000 1111 1110 1101 1100 1011 1010 1001 1000 +7 +6 +5 +4 +3 +2 +1 +0 -0 -1 -2 -3 -4 -5 -6 -7 Cryptography -Part -I 4 0111 0110 0101 0100 0011 0010 0001 0000 1111 1110 1101 1100 1011 1010 1001 1000 +7 +6 +5 +4 +3 +2 +1 +0 -1 -2 -3 -4 -5 -6 -7 -8 One’s Complement Two’s Complement
  • 5. Two’s Complement Number Representation and Value (1)  MSB represents negative number with a value.  Example: 8-bit number say  1101 0011  Value in decimal  = -1*27 + 1*26 + 0*25 + 1*24 + 0*23 +0*22 + 1*21 + 1  =-128 +64+0+16+0+0+2+1  =-128+83  =-45 Cryptography -Part -I 5
  • 6. Two’s Complement Number Representation and Value (2)  Example: 1111 1111  Decimal Value  = -1*27 + 1*26 + 1*25 + 1*24 + 1*23 +1*22 + 1*21 + 1  = -128+64+32+16+8+4+2+1 =-128+127 = -1  Example: 1000 0000 Value = -128  Example: 0111 1111 Value = 127 Cryptography -Part -I 6
  • 7. Finding a Negative of a number  Assume 1’s complement  Number 8-bit: 0000 1111; value =15  Given 15 determine -15  Change all 0 to 1 and 1 to zero  Result: 1111 0000 = -127+64+32+16 =-127+112 = -15  Assume 2’s complement  Number 8-bit: 0000 1111; value =15  Given 15 determine -15  Change all 0 to 1 and 1 to zero then add 1  Result: 1111 0001 = -128+64+32+16+1 =-128+113 = -15 7
  • 8. Arithmetic Operations in Two’s Complement (1)  Example:Find 7 – 5 assuming 4-bit numbers 7 = 0111 ; -5 =1011 in 2’s complement 0111 1011 ----- 10010 Carry in MSB 1, Carry out in MSB 1 Result ok value 2
  • 9. Arithmetic Operations in Two’s Complement (2)  Example:Find 7 + 5 assuming 4-bit numbers 7 = 0111 ; 5 =0101 in 2’s complement 0111 0101 ----- 1100 Carry in MSB 1, Carry out in MSB 0 Result wrong; value -4. We can not represent real value 12. This is overflow. 9
  • 10. Arithmetic Operations in Two’s Complement (2)  Example:Find 7 + 5 assuming 4-bit numbers 7 = 0111 ; 5 =0101 in 2’s complement 0111 0101 ----- 1100 Carry in MSB 1, Carry out in MSB 0 Result wrong; value -4. We can not represent real value 12. This is overflow. 9

Editor's Notes

  • #9: Given any positive integer n and any nonnegative integer a, if we divide a by n, we get an integer quotient q and an integer remainder r. In modular arithmetic we are only interested in the remainder (or residue) after division by some modulus, and results with the same remainder are regarded as equivalent. Two integers a and b are said to be congruent modulo n, if (a mod n ) = ( b mod n ) .