Skip to content
SoftwareSolutions.net
SEO, Website & Development

Twos complement calculator

Show a signed number in two's complement for a chosen bit width.

Try it

Ready

Inputs

Result

The result appears here as you type.

About Twos complement calculator

A two's complement calculator converts a signed binary number into its decimal value, or a negative decimal number into its two's complement binary form. Two's complement is the standard way computers store negative integers. Enter a value and a bit width, such as 8 or 16 bits, and the calculator shows the binary pattern and the decimal meaning. Programmers, students and engineers use it to check arithmetic and understand overflow.

The bit width matters. The same pattern can mean a different number at a different width, so always choose the width your system uses. The calculator works with whole numbers only and tells you when a value is outside the range the width can hold.

How to use Twos complement calculator

  1. Choose the bit width, such as 8, 16 or 32 bits.
  2. Enter a decimal number, positive or negative, or a binary pattern for the reverse conversion.
  3. Read the binary pattern in two's complement form.
  4. Check the range shown, which is from minus 2 to the power of width minus 1, up to 2 to the power of width minus 1 minus 1.
  5. Use the result to confirm how a value is stored in memory.

Finding the two's complement

To write a negative number in two's complement, write the positive value in binary with the chosen width, invert every bit, then add one. For −5 in 8 bits, the positive form 00000101 becomes 11111010 after inversion, and adding one gives 11111011. The leftmost bit is the sign bit, and a value with it set is negative.

Reading the number back is the reverse. If the leading bit is 1, subtract 2 to the power of the width from the unsigned value. The pattern 11111011 is 251 unsigned, and 251 minus 256 is −5.

Why computers use it

Two's complement lets addition and subtraction use the same circuitry for positive and negative values. There is only one representation of zero, and the arithmetic works without special cases. This is why almost every modern processor uses it.

Overflow happens when a result is outside the range of the width. Adding 1 to 127 in 8 bits gives −128, which is a wrap-around rather than an error the hardware reports. Check the range before relying on results near the limits.

Frequently asked questions

Why does the width change the answer?

The width sets how many bits are available. The same pattern represents a different value at 8 bits than at 16 bits.

What is the range of an 8-bit signed number?

From −128 to 127.

Is two's complement used for decimals?

This calculator covers whole numbers. Floating-point numbers use a different format with a sign, exponent and mantissa.

Related tools

Tools that pair well with this one.