Skip to content
๐Ÿง  Arithmetic Overflow in Binary Systems

๐Ÿง  Arithmetic Overflow in Binary Systems

๐Ÿ” Motivation

Arithmetic overflow occurs when the result of an operation exceeds the representable range of a fixed-width binary system.

Itโ€™s not a computational errorโ€”itโ€™s a representation mismatch between the result and the available bit space.

Overflow is especially critical in signed systems, where the MSB encodes sign, and the range is asymmetric.


๐Ÿงฎ Representational Limits

Bit Width (n)Unsigned RangeSigned (Twoโ€™s Complement)
4 bits0 to 15โˆ’8 to +7
8 bits0 to 255โˆ’128 to +127
16 bits0 to 65,535โˆ’32,768 to +32,767

โš ๏ธ Overflow Scenarios

โœ… Valid Addition

  0101 (5)
+ 0010 (2)
-----------
= 0111 (7) โ† within range

โŒ Overflow: Positive + Positive โ†’ Negative

  0111 (+7)
+ 0001 (+1)
------------
= 1000 (โˆ’8) โ† overflow!

โŒ Overflow: Negative + Negative โ†’ Positive

  1011 (โˆ’5)
+ 1010 (โˆ’6)
------------
= 0101 (+5) โ† overflow!

โœ… Valid Subtraction

  00010101 (+21)
โˆ’ 00001111 (+15)
-----------------
= 00000110 (+6) โ† within range

โŒ Overflow: Positive โˆ’ Negative โ†’ Too Positive

  01111111 (+127)
โˆ’ 11111111 (โˆ’1)
------------------
= 10000000 (โˆ’128) โ† overflow!

โŒ Overflow: Negative โˆ’ Positive โ†’ Too Negative

  10000000 (โˆ’128)
โˆ’ 01111111 (+127)
------------------
= 00000001 (+1) โ† overflow!

๐Ÿ”ง Detection Logic

๐Ÿง  XOR Method (Addition Only)

Overflow occurs iff: Carry into MSB โ‰  Carry out of MSB

Overflow = Cin โŠ• Cout

Where:

  • Cin = carry into MSB
  • Cout = carry out of MSB

This method is hardware-optimized and applies only to addition.


๐Ÿง  Sign Rule (Generalized)

OperationOverflow Condition
AdditionOperands have same sign, result has different sign
SubtractionOperands have different signs, result sign โ‰  minuend sign

This rule is semantic and works for both addition and subtraction.


๐Ÿ” Semantic Resonance: Overflow as Wraparound

Think of binary arithmetic as a circular number line:

  • Adding beyond the max wraps around to the negative zone
  • Subtracting below the min wraps around to the positive zone

This is a modular artifact, not a logical failure.


๐Ÿง  Vault Hooks

  • Audit Checklist: Validate MSB transitions, operand signs, and result sign
  • Overflow Map: Diagram signed vs unsigned wraparound zones
  • Teaching Analogy: Overflow as โ€œclock arithmeticโ€ with sign flips
  • Pipeline Module: Embed XOR-based overflow detection for addition, and sign-rule logic for subtraction
  • Semantic Validator: Compare operand signs and result sign to flag representational collapse
Last updated on