digiwleea Tools
Learn Open the lab →

Two's complement calculator

Convert a decimal number to its two's complement binary at 8, 16, or 32 bits, or paste a bit pattern to read off the signed value it represents. For negative numbers the invert-and-add-1 steps are shown, and the range of values that fit in the chosen width is always displayed. For example, -1 at 8 bits is 11111111.

How to use it

Pick a bit width (8, 16, or 32) with the buttons. Type a whole number, positive or negative, in the Decimal box to see its two's-complement bit pattern, or type a pattern of 0s and 1s in the Binary box to decode it back to a signed decimal. The two boxes stay in sync, and if a value will not fit in the chosen width you get a note telling you the range instead of a wrong answer.

When the number is negative, the steps panel shows the textbook method: write the magnitude in binary, flip every bit (the one's complement), then add 1. When the number is zero or positive, two's complement is identical to plain binary, so only the bit pattern is shown.

Worked example: -1 at 8 bits

Start from the magnitude: 1 in 8-bit binary is 00000001. Invert every bit to get the one's complement, 11111110. Add 1, which carries all the way up to give 11111111. So -1 in 8-bit two's complement is 11111111, all ones.

To check it, read 11111111 back as a signed value: the leftmost bit is 1, so the number is negative, and the two's-complement rule says its value is the unsigned reading (255) minus 256 (which is two to the eighth), giving -1. The all-ones pattern is always -1, at any width.

Why two's complement

Two's complement is how nearly every computer stores signed integers, because it lets the same adder hardware add positive and negative numbers with no special case: subtraction a - b is just a + (two's complement of b), and any overflow carry off the top is simply dropped. There is also exactly one representation of zero (all zeros), unlike the sign-and-magnitude scheme which wastes a pattern on "negative zero".

The cost is that the range is lopsided by one: an n-bit value runs from -(2^(n-1)) to 2^(n-1) - 1, so 8 bits cover -128 to 127. The most significant bit doubles as the sign: 0 means non-negative, 1 means negative. See it drive real subtraction in the subtraction lesson, then build it in the lab.

Frequently asked

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

Take the magnitude (the number without its sign) in binary at your chosen bit width, invert every bit, then add 1. For -1 at 8 bits: 1 is 00000001, inverting gives 11111110, adding 1 gives 11111111. So -1 is 11111111.

What is -1 in two's complement at 8 bits?

-1 in 8-bit two's complement is 11111111 (all ones). The pattern of all 1s is always -1 in two's complement, at any width: 16-bit is 1111111111111111, and so on.

What range of numbers fits in two's complement?

An n-bit two's complement value ranges from -(2 to the power n-1) up to 2 to the power n-1 minus 1. So 8 bits hold -128 to 127, 16 bits hold -32768 to 32767, and 32 bits hold -2147483648 to 2147483647. There is one more negative value than positive because zero takes a positive slot.

Two's complement is what makes subtraction reuse the adder. Read the subtraction lesson, then open the lab and wire up a subtractor from an adder and inverters.

Related tools: binary converter and base converter.

Open the lab →

Embed this tool

Free to embed in your course page, blog, or notes: just keep the credit link under the widget. Paste this where you want it:

<iframe src="https://digiwleea.wleeaf.dev/embed/tool/?w=twos-complement" width="100%" height="480" style="border:0;border-radius:12px;max-width:720px" title="Two's complement converter" loading="lazy"></iframe>