Two’s complement is how virtually every computer stores negative integers. Its genius is that addition and subtraction work the same for signed and unsigned numbers, so one adder circuit handles both.
How to use the Two’s Complement Calculator
- Number of bits
- Conversion
- Decimal number
- Binary number
Everything is calculated in your browser, so results appear instantly and nothing you type is sent to a server.
How it works
Choose the number of bits and the direction. The steps show the binary of the absolute value, the inverted bits and the final pattern.
Formula
Negative x: invert the bits of |x| and add 1 · range for n bits: −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1
Worked example
Inputs — Number of bits: 8; Conversion: Decimal → two's complement; Decimal number: -5.
Results — Result = 1111 1011; Binary of the absolute value / input = 0000 0101; Inverted bits = 1111 1010; Decimal value = -5; Steps = Write |-5| in binary (00000101), flip every bit (11111010) and add 1..
Key terms
- Sign bit
- The leftmost bit, 1 for negative numbers.
Frequently asked questions
What is −1 in 8-bit two's complement?
1111 1111.
What is the range of an 8-bit signed integer?
−128 to 127.
How do I tell if a two's-complement number is negative?
Its leftmost bit is 1.
Why add 1 after inverting?
So that there is only one zero and arithmetic works naturally.