Two’s Complement Calculator

Decimal ↔ two’s complement binary for 4 to 64 bits, with hex, one’s complement and every step.

Computed in your browser — nothing is sent

Two’s Complement Calculator

Scan with a phone camera to open this page

sofritools.com/twos-complement-calculator/

WhatsApp

Convert decimal numbers to two’s complement binary — and back — step by step

—Signed decimal
—Hexadecimal
—Read as unsigned
—One’s complement
—Range

How two’s complement works

Quick answer: to write a negative number in two’s complement, take its absolute value in binary using the full number of bits, invert every bit, and add 1. For −5 in 8 bits: 5 = 0000 0101 → invert → 1111 1010 → add 1 → 1111 1011. Positive numbers are ordinary binary padded with zeros, and the first bit is the sign: 0 for positive, 1 for negative. Reading one back is the same trick in reverse — if the first bit is 1, invert and add 1 to get the size, then put a minus sign in front.

n bits hold the values from −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1 — −128 to 127 in 8 bits — which is why the calculator checks the range for the width you pick. Computers use two’s complement because there is a single zero and ordinary binary addition works for negative numbers with no special cases: 5 + (−5) = 0000 0101 + 1111 1011 = 1 0000 0000, and the carry out of the top bit is simply dropped. The result also shows the pattern in hexadecimal (FB), what the same bits mean read as unsigned (251), and the one’s complement form. Everything runs in your browser.

4-bit two’s complement table

BitsUnsignedTwo’s complementOne’s complement
0000000
0001111
0010222
0011333
0100444
0101555
0110666
0111777
10008−8−7
10019−7−6
101010−6−5
101111−5−4
110012−4−3
110113−3−2
111014−2−1
111115−1−0

Ranges by number of bits

BitsSmallestLargest
4−87
8−128127
16−32,76832,767
32−2,147,483,6482,147,483,647
64−9,223,372,036,854,775,8089,223,372,036,854,775,807

Common mistakes

MistakeWhy it is wrongInstead
Inverting before padding to the full width101 inverted is 010, but 5 in 8 bits is 0000 0101, which inverts to 1111 1010.Write all n bits first, then invert.
Adding 1 before invertingThe order matters: invert, then add 1.5 → 0000 0101 → 1111 1010 → 1111 1011.
Reading a negative pattern as unsigned1111 1011 is 251 unsigned but −5 in two’s complement.Check the first bit before reading the value.
Choosing too few bits200 does not fit in 8 signed bits (max 127).Use 16 bits, or the unsigned reading.
Extending a negative number with zeros1011 (−5 in 4 bits) padded to 0000 1011 becomes +11.Sign-extend: copy the first bit — 1111 1011.

Reference tables

FAQ

What is the range of an 8-bit two’s complement number?

−128 to 127. In general, n bits cover −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1: 4 bits −8 to 7, 16 bits −32,768 to 32,767, 32 bits −2,147,483,648 to 2,147,483,647. There is one more negative number than positive because zero takes one of the non-negative patterns.

How do you convert two’s complement to decimal?

Look at the first bit. If it is 0, read the number as ordinary binary. If it is 1, invert all the bits, add 1, and put a minus sign in front: 1111 1011 → 0000 0100 → 0000 0101 = 5 → −5. Shortcut: the first bit is worth −2ⁿ⁻¹ and the rest add normally, so −128 + 123 = −5.

What is the difference between one’s and two’s complement?

One’s complement just inverts the bits; two’s complement inverts them and adds 1. One’s complement has two zeros (0000 and 1111 in 4 bits) and a range of −7 to 7; two’s complement has a single zero and reaches −8. That single zero, and the fact that plain addition works, is why every modern computer uses two’s complement.

Related tools