Fixed-Width Integer Arithmetic and Overflow
Compare mathematical results with stored bit-pattern values in fixed-width integer arithmetic.
Results
—
- Mathematical result
- —
- Out of range (overflow / underflow)
- —
- Stored bit pattern (hexadecimal)
- —
- Stored bit pattern (binary)
- —
- Representable range
- —
Results update automatically when the required values are entered.
Method, applicability and sources
Calculation method
For bit width n and mathematical integer result M, let U=M mod 2^n, in the range 0–2^n−1. The unsigned stored value is U. The signed two's complement stored value is U if U<2^(n−1), otherwise U−2^n. The result is out of range if M is outside 0–2^n−1 for unsigned integers or −2^(n−1)–2^(n−1)−1 for signed integers. Integer division truncates toward 0; the remainder has the same sign as the dividend. Division by 0 is undefined. Intermediate results are not rounded, and displayed integers are not abbreviated.
Worked example (hypothetical values)
For signed 8-bit integers, 127+1 is mathematically 128 but is stored as −128 (0x80), so it is out of range. For unsigned 8-bit integers, 255+1 is mathematically 256 but is stored as 0 (0x00), also out of range.
Applicability and limitations
Checking arithmetic results for signed two's complement or unsigned n-bit integers. Does not guarantee signed-overflow runtime behavior in C/C++ or other languages. Excludes floating-point error, shifts, bitwise logic, and IP address range calculations.
Method and sources
Method: E087 v1.0 / ECMA-262 2026 §21.2.2.1–2. Data recorded: 2026-11-13.