๐ง 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 Range | Signed (Twoโs Complement) |
|---|---|---|
| 4 bits | 0 to 15 | โ8 to +7 |
| 8 bits | 0 to 255 | โ128 to +127 |
| 16 bits | 0 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)
| Operation | Overflow Condition |
|---|---|
| Addition | Operands have same sign, result has different sign |
| Subtraction | Operands 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