Skip to content
Calc.

Two's Complement Calculator (4, 8, 16 and 32-bit)

Write a signed decimal integer as a two's complement binary pattern of 4, 8, 16 or 32 bits, or read a binary pattern back as its signed and unsigned values. Explains the flip-and-add-one rule, the range of each bit width and overflow.

Last updated: October 2026

Two's complement pattern

10101010 (hex AA)

Formula below · 3 sources (cs.lmu.edu, doc.ic.ac.uk, mathsisfun.com) · Updated Oct 2026

Compare with similar

About this calculator

Two's complement is how almost every processor stores signed integers. In an n-bit word the top bit carries a weight of -2ⁿ⁻¹ instead of +2ⁿ⁻¹, and the other bits keep their normal weights. So in 8 bits the pattern 10101010 is -128 + 32 + 8 + 2 = -86, while read as an unsigned byte the same pattern is 170. Positive numbers 0 to 2ⁿ⁻¹ - 1 look exactly like ordinary binary with a leading 0; negative numbers from -1 down to -2ⁿ⁻¹ have a leading 1.

To negate a number: invert every bit and add 1. For -86 in 8 bits, start from 86 = 01010110, invert to 10101001, add 1 to get 10101010. The same steps turn a negative pattern back into its magnitude. Equivalently, a negative value v is stored as the unsigned pattern of v + 2ⁿ: -86 + 256 = 170 = 10101010₂, which is what this calculator computes, and it is why -1 is all ones (FF in hex) at any width.

The ranges are -8 to 7 (4 bits), -128 to 127 (8 bits), -32,768 to 32,767 (16 bits) and -2,147,483,648 to 2,147,483,647 (32 bits). A value outside the range cannot be represented: the calculator says so rather than silently wrapping around, which is what a CPU does on overflow (127 + 1 becomes -128 in int8). The scheme is popular because addition, subtraction and multiplication of the low bits work with the same circuits as for unsigned numbers, and there is only one zero.

When reading a pattern, bits are padded on the left with zeros to the chosen width, so 1010 read as 8 bits is 00001010 = 10; read as 4 bits it is -6. Choose the width that matches the data type you are working with (int8, int16, int32).

How to use

Example (the defaults): -86 in 8 bits. The magnitude 86 is 64 + 16 + 4 + 2 = 01010110. Invert the bits: 10101001. Add 1: 10101010. In hex that is AA. Check: -128 + 32 + 8 + 2 = -86. Alternatively -86 + 256 = 170 = 10101010₂. Binary to decimal: choose the second mode, keep 10101010 and 8 bits. The leading 1 marks a negative number, so subtract 256 from the unsigned value 170: -86 signed, 170 unsigned. The same pattern in 16 bits is 0000000010101010, which is +170 either way. A 16-bit example: -1000 is 1000 = 0000001111101000, inverted 1111110000010111, plus 1 = 1111110000011000 (FC18). And 127 + 1 in 8 bits: 01111111 + 1 = 10000000, which the calculator reads as -128, the classic overflow.

Frequently asked questions

Why do computers use two's complement instead of a sign bit?

With a plain sign bit (sign-magnitude) there are two zeros (+0 and -0) and the adder has to check signs and subtract magnitudes. In two's complement, adding a negative number is the same as adding its unsigned pattern and discarding the carry out, so one adder handles both signed and unsigned arithmetic, zero is unique, and comparisons stay simple. That is why C, Java, Rust and every mainstream CPU define int8, int16, int32 and int64 this way.

How do I find the two's complement of a number by hand?

Write the positive magnitude in binary with the full number of bits, flip every bit (0 becomes 1, 1 becomes 0), then add 1. For -5 in 4 bits: 5 = 0101, flipped 1010, plus 1 = 1011. A quicker trick: copy the bits from the right up to and including the first 1, then flip everything to the left of it. 0101 keeps the trailing 1 and flips 010 to 101, giving 1011 directly.

What is the range of an 8-bit, 16-bit or 32-bit signed integer?

An n-bit two’s complement integer runs from -2ⁿ⁻¹ to 2ⁿ⁻¹ - 1. For 8 bits that is -128 to 127, for 16 bits -32,768 to 32,767, for 32 bits -2,147,483,648 to 2,147,483,647 and for 64 bits about ±9.22 × 10¹⁸. The negative side has one more value because the pattern 100…0 is the most negative number and has no positive counterpart.

What happens on overflow?

The result wraps around modulo 2ⁿ. In int8, 127 + 1 gives 10000000, which is -128, and -128 - 1 gives 01111111 = 127. Hardware sets an overflow flag; many languages ignore it (C declares signed overflow undefined behaviour, Java wraps silently, Rust panics in debug builds). This calculator refuses an out-of-range input instead of wrapping, and tells you the range for the chosen width so you can pick a wider one.

How is a negative number shown in hexadecimal?

The same way: the two’s complement bit pattern is grouped in fours and written in hex, so -1 is FF (8-bit), FFFF (16-bit) or FFFFFFFF (32-bit) and -86 is AA. Note that the hex form depends on the width: -86 is AA as a byte but FFAA as a 16-bit value. The calculator prints the hex alongside the binary for the width you chose.

Related calculators

Sources & references

Think a result is wrong? Report a problem with this calculator.