# Two’s Complement Calculator

URL: https://speedycalculator.com/calculators/math/twos-complement/
Last updated: 2026-10-30

> The two's complement calculator converts a signed decimal integer to its two's-complement binary form for 4 to 64 bits, or decodes a two's-complement binary number back to decimal.

## Inputs

- Number of bits
- Conversion
- Decimal number
- Binary number

## Results

- Result
- Binary of the absolute value / input
- Inverted bits
- Decimal value
- Steps

## Formula

```
Negative x: invert the bits of |x| and add 1 · range for n bits: −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1
```

## Explanation

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.

## 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.

## FAQ

**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.


## Sources

- [Wolfram MathWorld – Binary](https://mathworld.wolfram.com/Binary.html)
- [Harvard CS50 – Binary and bitwise operators](https://cs50.harvard.edu/x/)
