Two's Complement Calculator

Convert signed decimal values or binary bit patterns to 4-, 8-, 16-, or 32-bit two's complement representations.

Calculate two's complement
Enter a signed decimal integer or a binary value beginning with 0b.

Examples: -5 or 0b11111011

About two's complement

Two's complement is the standard representation for signed integers in modern computers. It uses a fixed number of bits and assigns the highest bit a negative positional weight. An 8-bit pattern therefore represents values from -128 through 127. The same eight bits can also be read as an unsigned value from 0 through 255, so the chosen interpretation matters whenever binary data is exchanged or displayed. Positive values look like ordinary binary numbers padded with leading zeroes. To form a negative value by hand, write the positive magnitude in the selected width, invert every bit, and add one. For example, decimal 5 is 00000101 in eight bits. Inverting produces 11111010 and adding one produces 11111011, the eight-bit representation of -5. The calculator reaches the same answer using arithmetic modulo 2 raised to the bit width. Bit width is part of the value's representation. Negative five is 1011 in four bits, 11111011 in eight bits, and 1111111111111011 in sixteen bits. Extending a signed negative value repeats the leading one, a process called sign extension. Extending a positive value repeats the leading zero. Removing bits can change the value when discarded bits are significant, which is why this calculator rejects decimal numbers outside the selected signed range. To decode a pattern, inspect its leading bit. If that bit is zero, the signed and unsigned interpretations are identical. If it is one, subtract 2 raised to the width from the unsigned value. Thus 11111011 is unsigned 251, but 251 - 256 gives signed -5. This direct rule is often quicker than reversing the invert-and-add-one procedure. Two's complement has useful arithmetic properties. Addition and subtraction use the same binary adder for signed and unsigned values, with overflow handled according to context. There is only one representation of zero, unlike one's complement. The asymmetric range includes one additional negative value because zero occupies a nonnegative pattern. This calculator is useful for computer architecture, digital logic, embedded programming, network protocols, debugging, and discrete mathematics. Always match the selected width to the system or data type you are studying. A pattern without its width and signedness is incomplete information, and interpreting it under a different convention can produce a completely different decimal result.

Two's complement examples

Decimal and widthBinary patternExplanation
-5 at 8 bits11111011Invert 00000101 and add one.
-8 at 4 bits1000This is the minimum signed four-bit value.
42 at 8 bits00101010Positive values use ordinary padded binary.

How to use the two's complement calculator

  1. Enter a signed decimal integer or a binary pattern with a 0b prefix.
  2. Choose the bit width used by the target system.
  3. Select Calculate two's complement.
  4. Compare the binary, signed decimal, and unsigned decimal interpretations.

Two's complement FAQ

Why does bit width matter?

The width determines the modulus and signed range. The same number has different padding and may not fit at a smaller width.

What range fits in eight bits?

An eight-bit two's complement integer ranges from -128 to 127. Its unsigned bit pattern ranges from 0 to 255.

How do I negate a binary number?

Within a fixed width, invert every bit and add one. Applying the process again returns the original value except for the minimum representable integer.

Why are signed and unsigned results different?

They assign different positional meaning to the highest bit. The stored bits are identical, but the interpretation changes.

Does two's complement have negative zero?

No, it has one all-zero representation for zero. This is an important advantage over sign-magnitude and one's complement systems.