SlideShare a Scribd company logo
Grokking Signed Overflows
Detecting an overflow when adding two signed numbers
Grokking Signed Numbers
Grokking Signed Numbers
• When a number is signed, the high digit represents
the additive inverse of what it typically would
• For instance, with a 4 bit signed nibble:
0 0 0 0

-8 4 2 1
• Instead of the high bit representing 8, with a signed
number it would represent negative 8
Grokking Signed Numbers
• With our four bit signed nibble, 7 is the highest
integer our signed nibble can represent
0 1 1 1 = 7

-8 4 2 1 .

( 0 + 4 + 2 + 1) .
Grokking Signed Numbers
• If we set the -8 place only, we get the lowest integer
our signed nibble can represent, -8
1 0 0 0 =-8

-8 4 2 1 .

(-8 + 0 + 0 + 0) .
Grokking Signed Numbers
• If we set the -8 place and the 1 place, we add one to
negative eight, for a total of -7
1 0 0 1 =-7

-8 4 2 1 .

(-8 + 0 + 0 + 1) .
Grokking Signed Numbers
• With our four bit signed nibble, we can represent all
integers from -8 to +7
1000 -8
1001 -7
1010 -6
1011 -5
1100 -4
1101 -3
1110 -2
1111 -1
0000 0
0001 +1
0010 +2
0011 +3
0100 +4
0101 +5
0110 +6
0111 +7
Grokking Signed Numbers
• Because of how the numbers are arranged, we can
do binary addition without worrying about the sign
1101 -3 13

+0010 +2 2

────00 00000

1111 -1 15
Grokking Signed Overflows
Grokking Signed Overflows
• When adding two numbers with a different sign bit,
the sum will NEVER overflow
1000 -8

+0001 +1

──── .

1001 -7
No overflow
• Sums will only overflow when both
addends have the same sign bit.
• Adding two positive numbers should never result in
a negative number
• Adding two negative numbers should never result in
a positive number
Grokking Signed Overflows
• When adding two signed positive numbers, if the
sign bit of the sum is set, an overflow has occurred
• When adding two negative numbers, if the sign bit of
the sum is not set, an overflow has occurred
Grokking Signed Overflows
Grokking Signed Overflows
Detecting an overflow when adding two signed numbers
Grokking Signed Overflows by Pat Hawks is licensed under a

Creative Commons Attribution 4.0 International License

More Related Content

What's hot

Year 5 Numeracy
Year 5 NumeracyYear 5 Numeracy
Year 5 Numeracy
Qwizdom UK
 
Emma Unit2 Scribepost
Emma Unit2 ScribepostEmma Unit2 Scribepost
Emma Unit2 Scribepost
guest52e65b
 
2s complement arithmetic
2s complement arithmetic2s complement arithmetic
2s complement arithmetic
Sanjay Saluth
 
1s and 2s complement
1s and 2s complement1s and 2s complement
1s and 2s complement
Then Murugeshwari
 
binary arithmetic rules
binary arithmetic rulesbinary arithmetic rules
binary arithmetic rules
student
 
Digital logic design lecture 02
Digital logic design   lecture 02 Digital logic design   lecture 02
Digital logic design lecture 02
FarhatUllah27
 
Digital logic mohammed salim ch2
Digital logic mohammed salim ch2Digital logic mohammed salim ch2
Digital logic mohammed salim ch2
Asst Lect Mohammed Salim
 
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
AmberSinghal1
 
Addition groups of 10
Addition groups of 10Addition groups of 10
Addition groups of 10
NotesMaster76
 
Number systems - binary, BCD, 2s comp
Number systems - binary, BCD, 2s compNumber systems - binary, BCD, 2s comp
Number systems - binary, BCD, 2s comp
mrlee2014
 
Binary Arithmetic
Binary ArithmeticBinary Arithmetic
Binary Arithmeticgavhays
 
Complements
ComplementsComplements
Complements
Sudheesh S Madhav
 
1sand2scomplement r004
1sand2scomplement  r0041sand2scomplement  r004
1sand2scomplement r004
arunachalamr16
 
How to make symbols with keyboard
How to make symbols with keyboardHow to make symbols with keyboard
How to make symbols with keyboard
Bhuwan Chalise
 
Binary addition
Binary additionBinary addition
Binary addition
Martin Jacob
 
Five Percent is One-Twentieth
Five Percent is One-TwentiethFive Percent is One-Twentieth
Five Percent is One-Twentieth
Jim Olsen
 
20 Percent is One-Fifth
20 Percent is One-Fifth20 Percent is One-Fifth
20 Percent is One-Fifth
Jim Olsen
 
ARITHMETIC FOR COMPUTERS
ARITHMETIC FOR COMPUTERS	  ARITHMETIC FOR COMPUTERS
ARITHMETIC FOR COMPUTERS
Amirthavalli Senthil
 

What's hot (19)

2's complement
2's complement2's complement
2's complement
 
Year 5 Numeracy
Year 5 NumeracyYear 5 Numeracy
Year 5 Numeracy
 
Emma Unit2 Scribepost
Emma Unit2 ScribepostEmma Unit2 Scribepost
Emma Unit2 Scribepost
 
2s complement arithmetic
2s complement arithmetic2s complement arithmetic
2s complement arithmetic
 
1s and 2s complement
1s and 2s complement1s and 2s complement
1s and 2s complement
 
binary arithmetic rules
binary arithmetic rulesbinary arithmetic rules
binary arithmetic rules
 
Digital logic design lecture 02
Digital logic design   lecture 02 Digital logic design   lecture 02
Digital logic design lecture 02
 
Digital logic mohammed salim ch2
Digital logic mohammed salim ch2Digital logic mohammed salim ch2
Digital logic mohammed salim ch2
 
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
 
Addition groups of 10
Addition groups of 10Addition groups of 10
Addition groups of 10
 
Number systems - binary, BCD, 2s comp
Number systems - binary, BCD, 2s compNumber systems - binary, BCD, 2s comp
Number systems - binary, BCD, 2s comp
 
Binary Arithmetic
Binary ArithmeticBinary Arithmetic
Binary Arithmetic
 
Complements
ComplementsComplements
Complements
 
1sand2scomplement r004
1sand2scomplement  r0041sand2scomplement  r004
1sand2scomplement r004
 
How to make symbols with keyboard
How to make symbols with keyboardHow to make symbols with keyboard
How to make symbols with keyboard
 
Binary addition
Binary additionBinary addition
Binary addition
 
Five Percent is One-Twentieth
Five Percent is One-TwentiethFive Percent is One-Twentieth
Five Percent is One-Twentieth
 
20 Percent is One-Fifth
20 Percent is One-Fifth20 Percent is One-Fifth
20 Percent is One-Fifth
 
ARITHMETIC FOR COMPUTERS
ARITHMETIC FOR COMPUTERS	  ARITHMETIC FOR COMPUTERS
ARITHMETIC FOR COMPUTERS
 

Similar to Grokking Signed Overflows

Chapter 2_Number system (EEEg4302).pdf
Chapter 2_Number system (EEEg4302).pdfChapter 2_Number system (EEEg4302).pdf
Chapter 2_Number system (EEEg4302).pdf
TamiratDejene1
 
09 binary number systems
09   binary number systems09   binary number systems
09 binary number systems
Lee Chadwick
 
Representation of Negative Numbers
Representation of Negative NumbersRepresentation of Negative Numbers
Representation of Negative Numbers
Forrester High School
 
chapter 2 part 2.pdf
chapter 2 part 2.pdfchapter 2 part 2.pdf
chapter 2 part 2.pdf
Praches1
 
Number bases
Number basesNumber bases
Parallel adders
Parallel addersParallel adders
Parallel adders
sana younas
 
Binary
BinaryBinary
Binary
mrsswenson
 
Lecture 06 computer arithmatic
Lecture 06 computer arithmaticLecture 06 computer arithmatic
Lecture 06 computer arithmatic
Obaidur Rahman
 
SD & D Negative Numbers
SD & D Negative NumbersSD & D Negative Numbers
SD & D Negative Numbers
Forrester High School
 
INTEGERS INTRO
INTEGERS INTROINTEGERS INTRO
INTEGERS INTRO
Orlando Calderon
 
Integers add
Integers addIntegers add
Integers add
summerportal8
 
Working With Binary Numbers
Working With Binary NumbersWorking With Binary Numbers
Working With Binary Numbers
adil raja
 
Unit-1 Digital Design and Binary Numbers:
Unit-1 Digital Design and Binary Numbers:Unit-1 Digital Design and Binary Numbers:
Unit-1 Digital Design and Binary Numbers:
Asif Iqbal
 
Signed numbers in 8051
Signed numbers in 8051Signed numbers in 8051
Signed numbers in 8051
Zeeshan Ahmed
 
L3 ARITHMETIC OPERATIONS.pptx
L3 ARITHMETIC OPERATIONS.pptxL3 ARITHMETIC OPERATIONS.pptx
L3 ARITHMETIC OPERATIONS.pptx
Harish257692
 
binary-numbers-system.doc.docx
binary-numbers-system.doc.docxbinary-numbers-system.doc.docx
binary-numbers-system.doc.docx
ArvindShukla81
 
Number system
Number systemNumber system
Number system
Sushil Subedi
 
A presentation on number system and conversion
A presentation on number system and conversionA presentation on number system and conversion
A presentation on number system and conversion
paudelsph
 
Digital fundamendals r001a
Digital fundamendals r001aDigital fundamendals r001a
Digital fundamendals r001a
arunachalamr16
 

Similar to Grokking Signed Overflows (20)

Chapter 2_Number system (EEEg4302).pdf
Chapter 2_Number system (EEEg4302).pdfChapter 2_Number system (EEEg4302).pdf
Chapter 2_Number system (EEEg4302).pdf
 
09 binary number systems
09   binary number systems09   binary number systems
09 binary number systems
 
Representation of Negative Numbers
Representation of Negative NumbersRepresentation of Negative Numbers
Representation of Negative Numbers
 
chapter 2 part 2.pdf
chapter 2 part 2.pdfchapter 2 part 2.pdf
chapter 2 part 2.pdf
 
Number bases
Number basesNumber bases
Number bases
 
Parallel adders
Parallel addersParallel adders
Parallel adders
 
Binary
BinaryBinary
Binary
 
Lecture 06 computer arithmatic
Lecture 06 computer arithmaticLecture 06 computer arithmatic
Lecture 06 computer arithmatic
 
SD & D Negative Numbers
SD & D Negative NumbersSD & D Negative Numbers
SD & D Negative Numbers
 
INTEGERS INTRO
INTEGERS INTROINTEGERS INTRO
INTEGERS INTRO
 
Integers add
Integers addIntegers add
Integers add
 
Working With Binary Numbers
Working With Binary NumbersWorking With Binary Numbers
Working With Binary Numbers
 
Unit-1 Digital Design and Binary Numbers:
Unit-1 Digital Design and Binary Numbers:Unit-1 Digital Design and Binary Numbers:
Unit-1 Digital Design and Binary Numbers:
 
Signed numbers in 8051
Signed numbers in 8051Signed numbers in 8051
Signed numbers in 8051
 
L3 ARITHMETIC OPERATIONS.pptx
L3 ARITHMETIC OPERATIONS.pptxL3 ARITHMETIC OPERATIONS.pptx
L3 ARITHMETIC OPERATIONS.pptx
 
binary-numbers-system.doc.docx
binary-numbers-system.doc.docxbinary-numbers-system.doc.docx
binary-numbers-system.doc.docx
 
Number system
Number systemNumber system
Number system
 
A presentation on number system and conversion
A presentation on number system and conversionA presentation on number system and conversion
A presentation on number system and conversion
 
Digital fundamendals r001a
Digital fundamendals r001aDigital fundamendals r001a
Digital fundamendals r001a
 
Digital Logic Rcs
Digital Logic RcsDigital Logic Rcs
Digital Logic Rcs
 

Recently uploaded

Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 

Recently uploaded (20)

Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 

Grokking Signed Overflows

  • 1. Grokking Signed Overflows Detecting an overflow when adding two signed numbers
  • 3. Grokking Signed Numbers • When a number is signed, the high digit represents the additive inverse of what it typically would • For instance, with a 4 bit signed nibble: 0 0 0 0
 -8 4 2 1 • Instead of the high bit representing 8, with a signed number it would represent negative 8
  • 4. Grokking Signed Numbers • With our four bit signed nibble, 7 is the highest integer our signed nibble can represent 0 1 1 1 = 7
 -8 4 2 1 .
 ( 0 + 4 + 2 + 1) .
  • 5. Grokking Signed Numbers • If we set the -8 place only, we get the lowest integer our signed nibble can represent, -8 1 0 0 0 =-8
 -8 4 2 1 .
 (-8 + 0 + 0 + 0) .
  • 6. Grokking Signed Numbers • If we set the -8 place and the 1 place, we add one to negative eight, for a total of -7 1 0 0 1 =-7
 -8 4 2 1 .
 (-8 + 0 + 0 + 1) .
  • 7. Grokking Signed Numbers • With our four bit signed nibble, we can represent all integers from -8 to +7 1000 -8 1001 -7 1010 -6 1011 -5 1100 -4 1101 -3 1110 -2 1111 -1 0000 0 0001 +1 0010 +2 0011 +3 0100 +4 0101 +5 0110 +6 0111 +7
  • 8. Grokking Signed Numbers • Because of how the numbers are arranged, we can do binary addition without worrying about the sign 1101 -3 13
 +0010 +2 2
 ────00 00000
 1111 -1 15
  • 10. Grokking Signed Overflows • When adding two numbers with a different sign bit, the sum will NEVER overflow 1000 -8
 +0001 +1
 ──── .
 1001 -7 No overflow
  • 11. • Sums will only overflow when both addends have the same sign bit. • Adding two positive numbers should never result in a negative number • Adding two negative numbers should never result in a positive number Grokking Signed Overflows
  • 12. • When adding two signed positive numbers, if the sign bit of the sum is set, an overflow has occurred • When adding two negative numbers, if the sign bit of the sum is not set, an overflow has occurred Grokking Signed Overflows
  • 13. Grokking Signed Overflows Detecting an overflow when adding two signed numbers Grokking Signed Overflows by Pat Hawks is licensed under a
 Creative Commons Attribution 4.0 International License