Calculate Two's Complement
Choose a conversion direction and bit width. The calculator runs in your browser and does not submit a form or reload the page when you calculate.
Conversion Results
Bit pattern
The leftmost bit is the sign bit. Bits are shown in groups of four for readability.
Calculation steps
Arithmetic check
What Is Two's Complement?
Two's complement is a widely used method for representing positive and negative integers in digital systems and computer architecture. It allows signed addition and subtraction to use ordinary fixed-width binary arithmetic.
How to calculate the two's complement of a negative number
- Choose a bit width, such as 8 bits.
- Write the absolute value of the negative number in binary, padded to that width.
- Invert every bit: replace each 0 with 1 and each 1 with 0.
- Add binary 1, keeping the result at the chosen width.
Positive 5: 00000101
Invert the bits: 11111010
Add 1: 11111011
Result: -5 is represented by 11111011 in 8-bit two's complement.
Two's-complement signed range
For a signed integer stored in n bits, the minimum representable value is negative 2 raised to n minus 1, and the maximum is 2 raised to n minus 1, minus 1.
| Bit width | Minimum | Maximum |
|---|---|---|
| 4-bit | -8 | 7 |
| 8-bit | -128 | 127 |
| 16-bit | -32,768 | 32,767 |
| 32-bit | -2,147,483,648 | 2,147,483,647 |
| 64-bit | -9,223,372,036,854,775,808 | 9,223,372,036,854,775,807 |
How to decode a two's-complement binary number
Interpret the bit pattern as an unsigned binary integer first. If its most significant bit is 0, the signed value equals the unsigned value. If the most significant bit is 1, subtract 2 raised to the bit width.
Unsigned value: 251
Bit width: 8
Signed value: 251 - 256 = -5
Two's complement versus one's complement
One's complement flips all bits but does not add 1. Two's complement flips all bits and then adds 1, keeping the result at the selected width. Two's complement has one representation of zero and is the standard representation used by most modern integer systems.
Why bit width must be specified
A bit pattern has a signed meaning only when its width
and interpretation are known. For example, the 8-bit
pattern 11111011 represents -5 in
two's complement, while the same pattern interpreted
as an unsigned integer equals 251.
This calculator rejects values outside the selected signed range rather than silently wrapping them. That makes it useful for learning binary arithmetic, checking fixed-width integer values, and understanding signed data representations.
Frequently Asked Questions
What is two's complement?
Two's complement is a binary representation for signed integers. For a fixed width of n bits, the representable range is from negative 2^(n-1) to positive 2^(n-1)-1.
How do I calculate two's complement?
For a negative number, write its positive magnitude using the selected bit width, invert every bit, and add 1. Keep the result at the selected width. Positive numbers are represented in ordinary binary with leading zeros.
Why does the bit width matter?
The bit width determines the range and representation. For example, -5 is 11111011 in 8-bit two's complement and 1111111111111011 in 16-bit two's complement.
What is the range of an n-bit signed integer?
The minimum is -2^(n-1) and the maximum is 2^(n-1)-1. An 8-bit signed integer ranges from -128 to 127.
How do I convert two’s-complement binary to decimal?
Interpret the bits as an unsigned integer. If the most significant bit is 0, that is the signed value. If it is 1, subtract 2 raised to the selected bit width from the unsigned value.
What does the most significant bit mean?
In a fixed-width two’s-complement representation, the most significant bit is the sign indicator. A 0 indicates a non-negative value, while a 1 indicates a negative value.
Can a positive number exceed the selected signed range?
No. The calculator rejects values outside the range for the selected bit width rather than silently wrapping or truncating them.
Is two’s complement the same as one’s complement?
No. One’s complement flips every bit. Two’s complement flips every bit and then adds 1, keeping the result at the selected width.