Two's Complement Calculator
Convert between signed and unsigned binary representations. Negate any integer in two's complement form, shown in binary, hex, and decimal across 8/16/32/64-bit widths.
How to Use
- Enter a decimal value (positive or negative).
- Pick bit width (8, 16, 32, or 64).
- See the two's complement binary, hex, unsigned equivalent, and manual steps.
Show Work
Formulas
History of Two\'s Complement
Binary representations of negative numbers have existed in three main flavors: sign-magnitude (one bit for sign, rest for magnitude), one\'s complement (flip all bits to negate), and two\'s complement (flip all bits and add 1). Early computers used all three: IBM 7090 (1959) was sign-magnitude; PDP-1 (1959) was one\'s complement; and IBM System/360 (1964) chose two\'s complement — a decision that ultimately became universal.
The reasons two\'s complement won: (1) only one representation of zero, avoiding a class of bugs where "zero equals zero" fails unexpectedly; (2) addition and subtraction work identically to unsigned — no separate ALU paths needed — so hardware is simpler; (3) sign extension (expanding 8-bit to 32-bit) just copies the MSB; (4) arithmetic overflow is detected by a single XOR of the carry in and out of the sign bit. No other sign convention offers all four advantages.
Today every mainstream CPU architecture — x86, ARM, RISC-V, POWER, SPARC, MIPS — uses two\'s complement for signed integers. C/C++ formalized it in the 2020 standard (prior versions left sign representation implementation-defined). The asymmetric range (one more negative value than positive) is the one practical caveat: negating INT_MIN produces INT_MIN again in two\'s complement, which is technically undefined in some languages.
About This Calculator
Enter any decimal integer and pick a bit width (8, 16, 32, 64). The tool returns the two\'s complement binary representation, hex value, equivalent unsigned interpretation (useful for debugging memory dumps), and flags whether the value fits within the chosen width.
Useful for: interpreting CPU debugger output, validating firmware that reads signed sensor values from memory-mapped registers, understanding why 127+1 wraps to −128 in 8-bit signed arithmetic, and converting between signed and unsigned interpretations of the same bit pattern. All math runs client-side.
Frequently Asked Questions
What is two's complement?
Standard way to represent negative integers in binary. To negate: flip all bits and add 1. The MSB becomes the sign bit. Used in nearly every modern CPU because addition/subtraction works the same as unsigned.
Why not sign-magnitude?
Sign-magnitude has two zeros (+0 and −0) and requires separate logic for addition. Two's complement has a single zero, simpler arithmetic, and uses one extra negative value (−128 for 8-bit vs −127 for sign-magnitude).
What range?
N-bit two's complement: −2^(N−1) to +2^(N−1)−1. 8-bit: −128 to +127. 16-bit: −32768 to +32767.
Common Use Cases
CPU Arithmetic
All modern CPUs use two's complement for signed integers.
Debugging Overflow
When 127+1 wraps to −128 in 8-bit signed arithmetic.
Bit Manipulation
Understanding bit patterns of negative numbers for masks and flags.
Last updated: