Twos Complement Calculator - Flip Bits, Add 1, Read the Signed Value

Use this twos complement calculator to enter a decimal or binary value, pick a bit width from 4 to 64, and read the 2s complement, signed value, and sign bit.

Updated: June 16, 2026 • Free Tool

Twos Complement Calculator

Pick the format of the value you want to enter.

Number of bits used to represent the value. The signed range updates to match.

Enter a non-negative integer for decimal mode, or paste a string of 0s and 1s for binary mode. Leading zeros are kept in binary mode so the input matches the exact bit pattern.

Results

Binary representation
0bits
Twos complement 0bits
Signed decimal value 0integer
Sign bit 0bit

What Is a Twos Complement Calculator?

A twos complement calculator takes a non-negative integer, applies the encoding modern CPUs use for signed binary numbers, and returns the bit pattern the hardware stores along with the signed decimal value the CPU will read back.

  • Reading the negative form of a binary number: Enter a positive decimal value and immediately see the bit pattern that stands in for the negative version in twos complement.
  • Converting a binary string to its twos complement: Paste a bit string from a register dump or a textbook exercise and read back the encoded negative value without manual flipping.
  • Working through a computer science homework set: Confirm a worked example from a class on signed binary representations without writing out 1s and 0s by hand.
  • Checking the signed range for a chosen bit width: Switch from 8 bits to 16 or 32 bits to see how the signed range of a twos complement value changes with the width.

Twos complement is the dominant signed binary encoding because it lets the CPU reuse ordinary binary addition for subtraction and gives the encoding a single zero. The most significant bit flags the sign, but the negative form is not a simple bitwise NOT of every position.

Type a value, pick a bit width, and the result panel shows the padded binary representation, the twos complement bit pattern, the signed decimal value, and the sign bit.

When the input arrives as a decimal value and you need it in binary, octal, or hexadecimal, the binary converter handles the same base conversions without the signed interpretation.

How the Twos Complement Calculator Works

The calculator reads the input as an unsigned integer, subtracts it from 2^width, and reduces the result modulo 2^width. The resulting bit pattern is the twos complement, and reading it as a signed integer gives the negative equivalent of the input.

twos_complement(n, width) = (2^width − n) mod 2^width
  • n: Unsigned integer value of the input, in decimal or read from a binary string. Must be in the range 0 to 2^width − 1.
  • width: Number of bits in the representation. The calculator accepts 4, 8, 12, 16, 32, and 64 bits.
  • range: Equal to 2^width. Subtracting n from the range and taking the result modulo range wraps overflow back into the bit width.
  • twos complement: The resulting bit pattern after the modular step, padded with leading zeros to the chosen bit width.

The modular step (2^width − n) mod 2^width is equivalent to inverting every bit and adding 1, but the subtraction form runs in a single BigInt step and avoids intermediate overflow in narrow bit widths. The CPU does the same with a NOT followed by an increment.

Decimal 87 in 8 bits

Mode: decimal, value: 87, width: 8 bits

n = 87, range = 2^8 = 256. Twos complement = (256 − 87) mod 256 = 169 = 10101001₂. The sign bit is 1, so the signed value is −87.

Binary 01010111, twos complement 10101001, signed value −87, sign bit 1.

The pattern 10101001 is the eight-bit twos complement of 87. The leading 1 marks the number as negative; the magnitude comes from 2^8 − 169 = 87, so the value is −87.

Decimal 1 in 8 bits

Mode: decimal, value: 1, width: 8 bits

n = 1, range = 256. Twos complement = (256 − 1) mod 256 = 255 = 11111111₂. The sign bit is 1, so the signed value is −1.

Binary 00000001, twos complement 11111111, signed value −1, sign bit 1.

In twos complement, −1 is always the all-ones pattern at the chosen width. That is why 1 + −1 (00000001 + 11111111 in 8 bits) overflows to 00000000 with no special case.

According to Wikipedia - Two's complement, the twos complement of an n-bit number is obtained by inverting all of its bits and adding 1, and the signed range for an n-bit representation runs from −2^(n−1) to 2^(n−1) − 1.

The flip and add-one behind this tool are part of the bitwise toolkit that the binary operations calculator exposes, alongside AND, OR, XOR, and shift operations on the same two-operand form.

Key Concepts Behind Twos Complement

These four ideas cover the encoding, why the range is asymmetric, and how twos complement compares to its older ones complement counterpart.

Flip every bit and add 1

The textbook recipe inverts each bit of the positive form and adds 1, which is what the CPU does with a bitwise NOT followed by an increment.

Sign bit and the most significant position

The first bit flags the sign: 0 means non-negative, 1 means negative. The magnitude of a negative value is recovered by subtracting the full bit pattern from 2^width, not by reading the lower bits.

Asymmetric range and a single zero

Twos complement reserves one slot for the most negative value, so the signed range runs from −2^(n−1) to 2^(n−1) − 1. The range is asymmetric by one, and 0 has a single encoding.

Twos complement vs ones complement

Ones complement flips every bit and ends up with two encodings for zero, while twos complement flips every bit and then adds 1, which removes the second zero and lets the encoding reuse ordinary binary addition.

The encoding is simple to compute but the consequences show up everywhere. The sign bit drives the signed decimal value, the modular step ensures the most negative value complements to itself, and the absence of a negative zero means binary addition can represent subtraction without a special case.

For the related question of how the encoding behaves under subtraction, the binary subtraction calculator walks through the twos complement rule that most CPUs actually use in hardware.

How to Use This Calculator

Pick a mode, choose a bit width, and type a value. The result panel updates as you change any field.

  1. 1 Pick the input mode: Choose Decimal integer when you have a base-10 value or Binary string when you are pasting a register dump or a bit string from a homework set.
  2. 2 Choose a bit width: Pick 4, 8, 12, 16, 32, or 64 bits. The signed range label updates to match, so you know which values fit before you type them.
  3. 3 Enter the value: Type a non-negative integer for decimal mode or a string of 0s and 1s for binary mode. The binary input must not exceed the chosen bit width.
  4. 4 Read the binary representation: Confirm the padded binary string in the result panel. The number of digits equals the chosen bit width, with leading zeros added on the left when the value is short.
  5. 5 Read the twos complement: The complement row shows the encoded bit pattern after the (2^width − n) mod 2^width step. The most significant bit of this row is the sign bit the encoding uses.
  6. 6 Read the signed value: Use the signed decimal value to confirm the negative equivalent. If the sign bit is 1, the signed value is negative and the magnitude is recovered by subtracting the pattern from 2^width.

Type 87 in decimal mode with 8 bits selected. The result panel shows binary 01010111, twos complement 10101001, signed value -87, and sign bit 1.

Once the twos complement is in hand and you need the sum of two such values, the binary addition calculator handles the column-by-column addition with carry that the encoding requires.

Benefits of Using the Twos Complement Calculator

The flip-and-add recipe is two steps, and the bookkeeping around it is the part that costs time. The twos complement calculator removes that bookkeeping.

  • Avoids manual bit flipping and add-one errors: Transcribing a long binary string, flipping each bit, and adding 1 by hand is the classic place to lose a digit. The calculator runs the modular step in a single BigInt operation.
  • Computes the signed value automatically: Reading the complement as a signed integer is a step the calculator does for you, including the most-negative-value case.
  • Handles every common bit width: Switching between 8, 12, 16, 32, and 64 bits updates the signed range label, the validation, and the binary string length in the same view.
  • Accepts both decimal and binary entry: Decimal mode fits textbook numbers, binary mode fits register dumps, and the result panel keeps the two views consistent.
  • Surfaces the sign bit as a separate field: The sign bit row makes it clear whether the complement should be read as non-negative or negative, which is the most common question in a signed binary exercise.

Use the calculator while working through a signed representations chapter, or keep it open while reading a CPU manual that describes how the arithmetic logic unit negates a value.

When the bit pattern is easier to read as base-16, the binary to hexadecimal calculator groups the binary digits into nibbles and renders the matching hex string.

Factors That Affect the Twos Complement

A handful of inputs change the result the calculator returns, and the limitations below cover the assumptions the encoding itself makes.

Bit width controls the range and the modulus

The range is 2^width, so widening the representation adds new bits to the complement. Switching from 8 bits (256) to 16 bits (65536) changes which values fit and which bit pattern is the most negative.

The most significant bit is reserved for the sign

The leading bit flags the sign. The signed range is −2^(n−1) to 2^(n−1) − 1, and the magnitude of a negative value is recovered by subtracting the full bit pattern from 2^width, not by reading the lower bits.

Decimal and binary entry share one pipeline

Binary mode converts the string to an unsigned integer first, then runs the same (2^width − n) mod 2^width step. The result is consistent across modes.

  • The most negative value in a twos complement system complements to itself. In 8 bits, 10000000 represents −128 and is the only negative value whose twos complement is the same pattern, a consequence of the modular arithmetic the encoding uses.
  • The calculator accepts bit widths from 4 to 64. Widths outside that range are not common in modern CPUs and are not supported, so users with a custom width should pad or truncate the result manually.
  • The calculator only computes the twos complement of a single value. Adding or subtracting two such values should be done with a binary addition or subtraction calculator, since the encoding only describes the representation.

The bit width is the only knob the user has to choose. The signed range and the validation both come from it, so changing the bit width is the first thing to try when a value does not fit.

According to Wikipedia - Signed number representations, twos complement is the dominant signed binary encoding used by modern general-purpose CPUs because it lets the same adder circuit handle both signed and unsigned values and gives the encoding a single zero.

If the wider context is hexadecimal arithmetic instead of pure binary, the hex calculator moves between hex, decimal, and binary in a single form.

Twos complement calculator showing decimal 87 in 8 bits becoming binary 01010111 and the 2s complement 10101001 with a signed value of -87
Twos complement calculator showing decimal 87 in 8 bits becoming binary 01010111 and the 2s complement 10101001 with a signed value of -87

Frequently Asked Questions

Q: What is a twos complement calculator?

A: A twos complement calculator applies the encoding that modern CPUs use for signed binary numbers and shows the bit pattern the hardware actually stores along with the signed decimal value the CPU will read back. The encoding takes a non-negative integer, subtracts it from 2^width, and reduces the result modulo 2^width.

Q: How do you calculate the twos complement of a binary number?

A: Pick a bit width, write the input as a binary string padded with leading zeros to that width, invert every bit, and then add 1. Equivalently, compute (2^width − n) mod 2^width, where n is the unsigned value of the input, in a single BigInt step.

Q: What is the twos complement of 7 in 8 bits?

A: In 8 bits, 7 is written as 0000 0111. Inverting every bit gives 1111 1000, and adding 1 gives the twos complement 1111 1001, which the CPU reads back as the signed value −7. The leading 1 flags a negative value, and the magnitude is recovered by subtracting the full pattern from 2^8: 256 − 249 = 7.

Q: What is the range of a signed 8-bit twos complement number?

A: A signed 8-bit twos complement number runs from −128 to +127. The sign bit costs one position on each side, and the encoding gives one extra slot to the most negative value (−128 in 8 bits) instead of a duplicate zero, which is why the range is asymmetric by one.

Q: Why does twos complement have only one representation of zero?

A: In twos complement, 0 is encoded as 0000 0000 in 8 bits and has no negative counterpart. Adding 1 to the all-ones bit pattern wraps back to 0000 0000, so the encoding gives 0 a single representation, which is one of the main reasons modern CPUs prefer it over ones complement.

Q: How is twos complement different from ones complement?

A: Ones complement flips every bit and ends up with a second representation of zero, while twos complement flips every bit and adds 1, which removes the second zero and lets the encoding reuse ordinary binary addition for subtraction. Twos complement is the dominant signed binary encoding on modern CPUs.