# Two's Complement Calculator

Convert between decimal and two's complement binary for 8-bit, 16-bit, or 32-bit integers. See step-by-step conversion and hex values. Free calculator.

## What this calculates

Convert any signed integer to its two's complement binary representation and back. Choose 8-bit, 16-bit, or 32-bit width, and see the binary, hexadecimal, unsigned equivalent, and step-by-step conversion.

## Inputs

- **Bit Width** — options: 8-bit (-128 to 127), 16-bit (-32768 to 32767), 32-bit (-2147483648 to 2147483647) — The number of bits used for the representation.
- **Decimal Value** — The signed integer to convert. Must fit in the selected bit width.

## Outputs

- **Two's Complement Binary** — formatted as text — The number in two's complement binary representation.
- **Hexadecimal** — formatted as text — The two's complement value in hexadecimal.
- **Unsigned Decimal Equivalent** — formatted as text — What the same bit pattern represents as an unsigned integer.
- **Valid Range** — formatted as text — The minimum and maximum values for the selected bit width.
- **Conversion Steps** — formatted as text — Step-by-step breakdown of the conversion process.

## Details

Two's complement is the standard method computers use to represent signed integers (positive and negative whole numbers) in binary.

**How Two's Complement Works:**

- **Positive numbers** are stored the same as regular binary, with a leading 0 bit.
- **Negative numbers** are stored by inverting all the bits of the absolute value and adding 1.

**Example (8-bit):**

The number -42:
1. Start with 42 in binary: 00101010
2. Invert all bits: 11010101
3. Add 1: 11010110

So -42 in 8-bit two's complement is 11010110.

**Why Two's Complement?**

- There is only one representation of zero (unlike sign-magnitude, which has +0 and -0).
- Addition and subtraction use the same hardware circuit.
- The most significant bit (MSB) acts as the sign bit: 0 for positive, 1 for negative.

**Ranges:**

- 8-bit: -128 to 127
- 16-bit: -32,768 to 32,767
- 32-bit: -2,147,483,648 to 2,147,483,647

## Frequently Asked Questions

**Q: What is two's complement?**

A: Two's complement is the most common way computers represent signed integers in binary. Positive numbers are stored as regular binary. Negative numbers are stored by flipping all the bits of the positive value and adding 1. This system lets CPUs use the same addition circuit for both positive and negative numbers.

**Q: How do I convert a negative number to two's complement?**

A: Start with the absolute value in binary, padded to the desired bit width. Invert every bit (0 becomes 1, 1 becomes 0). Then add 1 to the result. For example, -5 in 8-bit: 5 = 00000101, invert = 11111010, add 1 = 11111011.

**Q: Why not just use a sign bit?**

A: A simple sign bit (sign-magnitude) creates two representations of zero (+0 and -0), wastes a bit pattern, and requires special hardware for addition and subtraction. Two's complement avoids these problems: it has one zero, and the same adder circuit works for positive and negative numbers.

**Q: What happens when a two's complement number overflows?**

A: Overflow occurs when the result of an operation exceeds the range of the bit width. In 8-bit, 127 + 1 wraps around to -128. This is because the bit pattern 01111111 + 1 = 10000000, which represents -128 in two's complement. Programming languages handle this differently: some wrap silently, others throw errors.

---

Source: https://vastcalc.com/calculators/math/twos-complement
Category: Math
Last updated: 2026-04-08
