Racira Calculator

Two's Complement Calculator

Range for Selected Width
Signed Range−2^7 … 2^7−1
Unsigned Range0 … 2^8−1

Why Computers Use Two's Complement

Computer arithmetic needs a way to represent negative numbers that lets the same addition circuit handle both positive and negative operands. Two's complement achieves this elegantly: the most significant bit carries the sign, negative values are produced by inverting all bits and adding one, and — crucially — addition, subtraction, and multiplication work identically on signed and unsigned patterns. Adding 1 to 11111111 wraps to 00000000, which is why −1 plus 1 equals 0 without any special-case logic. This single property is why virtually every processor since the 1960s has used two's complement.

The range of an n-bit two's complement value is asymmetric: −2^(n−1) through +2^(n−1)−1. An 8-bit byte holds −128 to +127, a 16-bit word −32,768 to +32,767, and a 32-bit integer roughly ±2.1 billion. Programmers meet this asymmetry constantly — the classic off-by-one of signed overflow, the sentinel value of −128 in pixel data, and the reason unsigned types double the positive range at the cost of losing negative values. This calculator converts any integer into its two's complement representation at a chosen bit width and flags overflow so a wrapped result never sneaks into your code silently.

Reading the Bit Pattern

Each position in the binary output is a power of two, and in two's complement the most significant bit contributes negatively: for an 8-bit pattern, bit 7 is worth −128 rather than +128. The chart in this calculator plots every bit from least to most significant, and the breakdown table reports the signed value, the unsigned interpretation of the same pattern, and the hexadecimal shorthand. Change the bit width from 8 to 16 or 32 and watch the sign extension fill the new high-order bits — the same negative value gains leading ones in exactly the way a compiler's implicit widening does.

Frequently Asked Questions

Related Calculators