2's Complement Calculator
Convert between decimal and two's complement binary, or negate a binary value instantly.
Enter any whole number in base-10.
What is 2's Complement?
Two's complement is the most common way computers store signed integers (positive and negative whole numbers). It lets processors use one binary format for both arithmetic and sign handling, which keeps hardware and software simpler.
In an n-bit two's complement system:
- The leftmost bit is the sign bit (most significant bit).
- Positive values look like normal binary with leading zeroes.
- Negative values are represented by wrapping around modulo
2^n. - Range is
-2^(n-1)to2^(n-1)-1.
How to Use This Calculator
1) Decimal → Two's complement binary
Choose Decimal → Two's complement binary, set the bit width, and enter an integer. The calculator checks if your value fits in that width, then returns:
- The binary bit pattern
- Its hexadecimal form
- The allowed range for that bit width
2) Two's complement binary → Decimal
Choose Two's complement binary → Decimal, set the width, and enter a binary pattern. You can include spaces or underscores (for readability), and the tool will normalize it automatically.
3) Negate binary (find 2's complement)
This mode takes a binary number and computes its two's complement (invert bits, add 1), effectively giving you the negative of the original value in the same width.
Manual Method (So the Output Makes Sense)
Converting a negative decimal to two's complement
Example: represent -18 in 8 bits.
- Write +18 in binary:
00010010 - Invert bits:
11101101 - Add 1:
11101110
So -18 in 8-bit two's complement is 11101110.
Converting binary two's complement to decimal
If the leading bit is 0, it is non-negative. If the leading bit is 1, subtract 2^n from the unsigned value.
For 8-bit 11101110:
- Unsigned value = 238
- Signed value = 238 - 256 =
-18
Why Bit Width Matters
The same bit pattern can mean different values depending on width. Always specify width when doing conversions.
- 4-bit: -8 to +7
- 8-bit: -128 to +127
- 16-bit: -32768 to +32767
- 32-bit: -2147483648 to +2147483647
- 64-bit: -9223372036854775808 to +9223372036854775807
Common Mistakes
- Ignoring overflow: if a decimal value is out of range, it cannot be represented in that width without truncation.
- Forgetting fixed width: two's complement only makes sense with a defined number of bits.
- Dropping leading zeros: this can change interpretation in some contexts.
- Confusing sign-magnitude with two's complement: they are different encoding systems.
Where Two's Complement Is Used
- CPU arithmetic units (ALUs)
- Assembly language and machine code
- Embedded systems and microcontrollers
- Binary protocol design and debugging
- Digital logic courses and interview prep
Quick FAQ
Why is two's complement preferred?
It makes addition/subtraction circuitry uniform and eliminates separate handling for most negative arithmetic operations.
Can zero have two representations?
In two's complement, zero has exactly one representation: all bits zero.
What is the most negative value in n bits?
-2^(n-1). For 8 bits, that is -128 (10000000).
Can I use this tool for large values?
Yes. This calculator uses BigInt, so it safely handles common widths up to 64 bits without floating-point precision issues.