Two's Complement Calculator

Two's complement binary1111 1111 1001 1100
Unsigned interpretation65,436
HexadecimalFF9C
Representable range-32,768 to 32,767
How this was calculated
  1. Two's complement stores negative numbers by inverting the bits of the absolute value and adding 1, so the leftmost bit - the sign bit - carries a weight of minus 2 to the power of bits minus 1 and ordinary addition just works.
  2. For -100 in 16 bits: the unsigned pattern that represents it is 65,436, which is 1111 1111 1001 1100 in binary and FF9C in hexadecimal.
  3. The sign bit is 1 (negative): read the pattern as unsigned and you get 65,436; read it as two's complement and values from -32,768 to 32,767 are covered, with one more negative value than positive - the asymmetry behind the classic overflow bugs.
  4. To negate a two's complement number, flip every bit and add 1 - the same operation recovers the original, which is why subtraction circuits only need an adder and a row of inverters.

This two's complement calculator converts between decimal values and their two's complement bit patterns. Two's complement stores negative numbers by inverting the bits of the absolute value and adding 1, so the leftmost bit — the sign bit — carries a weight of minus 2 to the power of bits minus 1 and ordinary addition just works. For example, -100 in 16 bits is 1111 1111 1001 1100 — FF9C in hex, 65,436 read as unsigned. Positive numbers keep their own pattern: 42 in 8 bits is 0010 1010. And -1 in 32 bits is 1111 1111 1111 1111 1111 1111 1111 1111 — all ones, 4,294,967,295 unsigned, the classic sentinel value.

Two's complement is the accepted standard because it lets one set of addition circuits handle signed and unsigned values alike. Its range explains the familiar edge cases: an n-bit two's complement number covers -2^(n-1) to 2^(n-1) - 1, one more negative value than positive, the asymmetry behind classic overflow bugs. To negate a value, flip every bit and add 1. This page shows the formula, step-by-step workings, worked examples and sources so you can check each result by hand.

Worked examples

-100 in 16 bits

-100 in 16 bits is 1111 1111 1001 1100 - FF9C in hex, 65,436 read as unsigned. (-100 · 16-bit)

Two's complement binary1111 1111 1001 1100
Unsigned interpretation65,436
HexadecimalFF9C
Representable range-32,768 to 32,767

42 in 8 bits

42 in 8 bits is 0010 1010 - the pattern is the number itself when positive. (42 · 8-bit)

Two's complement binary0010 1010
Unsigned interpretation42
Hexadecimal2A
Representable range-128 to 127

-1 in 32 bits

-1 in 32 bits is 1111 1111 1111 1111 1111 1111 1111 1111 - all ones, 4,294,967,295 unsigned, the classic sentinel value. (-1 · 32-bit)

Two's complement binary1111 1111 1111 1111 1111 1111 1111 1111
Unsigned interpretation4,294,967,295
HexadecimalFFFF FFFF
Representable range-2,147,483,648 to 2,147,483,647

How two's complement works

Two's complement is the system most computers use to store signed integers, and the rule for building a negative number is simple: take the bits of its absolute value, invert every one of them, then add 1. That single procedure is why a two's complement calculator can produce a negative result so quickly — it never needs a separate minus sign. The leftmost bit becomes the sign bit, and in the two's complement interpretation it carries a weight of minus 2 to the power of bits minus 1. Every other bit keeps its usual positive weight. With that one negative weight in place, ordinary binary addition just works, even when one or both operands are negative.

A few concrete patterns make the idea easier to see. The number 42 in 8 bits is 0010 1010 — when the value is positive, the stored pattern is the number itself, with the leading bit at 0. Now consider -100 in 16 bits: it is 1111 1111 1001 1100, which is FF9C in hex and 65,436 if you read the same bits as an unsigned value. The bits have not changed; only the interpretation has. The same effect shows up at the extreme. In 32 bits, -1 is 1111 1111 1111 1111 1111 1111 1111 1111 — all ones, or 4,294,967,295 read as unsigned. That all-ones pattern is the classic sentinel value in many systems, standing in for "no value" or an error.

The range of an n-bit two's complement number runs from -2^(n-1) to 2^(n-1) - 1. Notice that the negative end reaches one step further than the positive end: there is one more negative value than positive value. That asymmetry is behind classic overflow bugs, because negating the most negative number cannot produce a valid positive counterpart in the same width. To negate any value, flip every bit and add 1 — the same invert-and-add-1 step used to encode a negative in the first place.

The elegance of the scheme is that subtraction needs no special hardware. Because the sign bit carries a negative weight, adding a negative number is just adding its bit pattern, so one adder handles both addition and subtraction. A two's complement calculator simply applies these rules to the width you choose, showing the bit pattern, the hex form, and the signed value side by side.

To negate a two's complement number: flip every bit, then add 1. The sign bit's weight of minus 2 to the power of bits minus 1 is what lets a single adder do both addition and subtraction.

Reading a pattern

Reading a two's complement pattern starts with a single question: what does the leftmost bit say? In two's complement, that leftmost bit is the sign bit, and it carries a weight of minus 2 to the power of bits minus 1. Every other bit keeps its usual positive weight, so ordinary addition just works across the whole pattern. If the sign bit is 0, the number is positive or zero and the pattern is simply the number itself. If the sign bit is 1, the pattern represents a negative number, and the negative weight of that top bit pulls the total below zero.

A positive example makes the rule concrete. In 8 bits, 42 is 0010 1010. The sign bit is 0, so nothing is subtracted, and the remaining bits add up to 42 exactly as you would read an ordinary binary number. This is why two's complement is often described as storing negative numbers by inverting the bits of the absolute value and adding 1: the positive case needs no special handling at all, and the same bit pattern means the same thing whether a circuit treats it as signed or unsigned.

Now read the same kind of pattern as a negative value. In 16 bits, -100 is 1111 1111 1001 1100, which is FF9C in hex. The leading bit is 1, so the sign bit contributes its large negative weight and the rest of the bits bring the total back up to -100. Read the identical pattern as unsigned, and you get 65,436. Neither reading is wrong; they are two interpretations of one bit string, and this is exactly where a two's complement calculator earns its place, letting you flip between the signed value and the unsigned value for the same pattern.

The most familiar negative pattern is all ones. In 32 bits, -1 is 1111 1111 1111 1111 1111 1111 1111 1111. Signed, it is -1. Unsigned, the same 32 bits read 4,294,967,295, the classic sentinel value that shows up whenever a program uses an unsigned field to mean "no value" or "maximum." A single pattern, two very different meanings, depending only on whether you honor the sign bit.

To go the other direction and negate a number, flip every bit and add 1. That rule is worth keeping in mind as a check on any pattern you read. It also explains the range: an n-bit two's complement number covers -2^(n-1) to 2^(n-1) - 1, one more negative value than positive. That asymmetry is behind classic overflow bugs, where the most negative value has no positive counterpart to flip to.

  • Sign bit 0: read the remaining bits as an ordinary unsigned value.
  • Sign bit 1: the top bit subtracts 2^(bits-1), so the total lands below zero.
  • Same bits, two readings: FF9C is -100 signed or 65,436 unsigned.
  • All ones in 32 bits: -1 signed, 4,294,967,295 unsigned.
Always check the leftmost bit before you total the rest. The pattern does not change — only your interpretation of the sign bit does.

Ranges and overflow

An n-bit two's complement number covers -2^(n-1) to 2^(n-1) - 1. That formula is worth unpacking, because it explains both the range you see in a two's complement calculator and the bugs that show up in real programs. The range has one more negative value than positive, and that asymmetry is the source of classic overflow errors.

At 8 bits, the range runs from -128 to 127. At 16 bits, it runs from -32,768 to 32,767. At 32 bits, it runs from -2,147,483,648 to 2,147,483,647. In every case the negative side holds one extra value, because zero occupies the pattern that would otherwise be the positive counterpart of the most negative number. The leftmost bit, the sign bit, carries a weight of minus 2 to the power of bits minus 1, and ordinary addition just works across the whole range.

The extra negative value is the one with no positive twin. Negating it by flipping every bit and adding 1 returns the same pattern, so its magnitude cannot be represented in the same width. This is where overflow bites: adding two large positives can push the result past the maximum and land on a negative number, and negating the most negative value leaves it unchanged.

The same bit patterns mean different things depending on how you read them. -100 in 16 bits is 1111 1111 1001 1100 - FF9C in hex, 65,436 read as unsigned. -1 in 32 bits is 1111 1111 1111 1111 1111 1111 1111 1111 - all ones, 4,294,967,295 unsigned, the classic sentinel value. A positive number such as 42 in 8 bits is simply 0010 1010, the pattern being the number itself. When a result wraps, the bits are truncated to the chosen width and reinterpreted, so the stored pattern stays valid while the signed value changes.

  • 8 bits: -128 to 127
  • 16 bits: -32,768 to 32,767
  • 32 bits: -2,147,483,648 to 2,147,483,647
  • Each width has one more negative value than positive
  • Negating the most negative value returns the same pattern
  • Adding past the maximum wraps to a negative result
  • The same bits read as unsigned can be far larger: FF9C is 65,436, all ones in 32 bits is 4,294,967,295
Overflow does not corrupt the bits - it changes what they mean. Truncate to the chosen width and the pattern is still a valid two's complement number, just not the one you expected.

Where it shows up

Two's complement is not an abstract exercise; it is the format underneath almost every integer you will ever touch. Every CPU integer type — the signed int, short, and long variables in compiled code — is stored this way, which is why a two's complement calculator is useful whenever you need to see what the machine actually holds rather than what the source code says. The rule is simple: negative numbers are stored by inverting the bits of the absolute value and adding 1, so the leftmost bit, the sign bit, carries a weight of minus 2 to the power of bits minus 1. Because of that weighting, ordinary addition just works across signed and unsigned values without special cases.

Positive values make the pattern easy to trust. 42 in 8 bits is 0010 1010 — the pattern is the number itself when positive. Negative values look stranger until you decode them. -100 in 16 bits is 1111 1111 1001 1100, which is FF9C in hex and 65,436 if the same bits are read as unsigned. That double identity is the heart of the format: the bits do not change, only the interpretation does.

Nowhere is that clearer than the classic sentinel value. -1 in 32 bits is 1111 1111 1111 1111 1111 1111 1111 1111 — all ones, or 4,294,967,295 unsigned. APIs and file formats have long used all-ones as a marker meaning "no value" or "end of list," and code that mixes signed and unsigned types can misread that marker in either direction.

The same bit patterns appear in the physical world. Signed sensor readings — temperatures below zero, accelerometer axes pointing the other way — arrive as two's complement integers, and a reader that treats them as unsigned will report a small negative temperature as a huge positive one. File formats that store offsets face the same issue: a negative offset is a legitimate value, and it is encoded with exactly this scheme.

The format's range explains a family of bugs. An n-bit two's complement number covers -2^(n-1) to 2^(n-1) - 1: one more negative value than positive, the asymmetry behind classic overflow bugs. The most negative value has no positive counterpart, so negating it — flip every bit and add 1 — returns the same value. When a calculation crosses that boundary, the result wraps instead of growing, and the error can be silent. Checking the sign bit and the range before you trust a result is the practical defense.

Remember the asymmetry: an n-bit value runs from -2^(n-1) to 2^(n-1) - 1, so the most negative number cannot be negated without overflowing.

FAQs

What is two's complement?

Two's complement is the standard signed integer encoding used in computers. To negate a number, you invert all of its bits and then add 1. This single method handles both positive and negative values, which is why it is the usual way machines store signed integers.

What is -100 in 16-bit two's complement?

In 16-bit two's complement, -100 is written as 1111 1111 1001 1100. Grouped into hex digits, that is FF9C. The leading ones show the value is negative, and the remaining bits encode the magnitude after the invert-and-add-1 step.

What is -1 in two's complement?

Negative one is all ones at any width. In 32 bits, -1 is 1111 1111 1111 1111 1111 1111 1111 1111. Because every bit is set, adding 1 to this pattern rolls over to zero, which is exactly the behavior you expect from -1.

What range does 16-bit two's complement cover?

A 16-bit two's complement value covers the range from -32,768 to 32,767. That gives 65,536 distinct patterns in total. Notice the negative end reaches one step further than the positive end, which is a normal feature of two's complement at every width.

How do I negate a two's complement number?

To negate a two's complement number, flip every bit and then add 1. The same operation works in both directions, so applying it to a positive value gives its negative and applying it to a negative value gives its positive. No separate rule is needed.

Why is there one more negative than positive?

Zero takes one of the non-negative patterns, leaving 2^(n-1) negative values and 2^(n-1) - 1 positive ones. Because zero is counted on the non-negative side, the negative side gets one extra slot. That is why a 16-bit value ranges from -32,768 to 32,767.

Sources

Related calculators

Binary Converter Calculator
Convert decimal numbers to binary, octal and hexadecimal — or read binary and octal numbers back into decimal — with the place-value working shown.
Bitwise Calculator (AND, OR, XOR)
AND, OR and XOR on two non-negative integers, with every result shown in decimal and in grouped binary so the bit patterns are easy to follow.
Number Base Converter
Number base converter: a decimal number in binary, octal and hexadecimal, with the bits and bytes it needs.