Two's Complement Calculator
Two's complement calculator. Convert decimal to two's complement and back, negate a binary or hex pattern, in 4, 8, 16 or 32 bits, with steps and ranges.
Published
Last updated
How the Two's Complement Calculator Formula Works
Two's complement stores signed integers in a fixed number of bits. The leading bit is the sign bit. An n-bit pattern covers the integers from -2n−1 to 2n−1 − 1, so 8 bits covers -128 to 127.
A non-negative number is written as ordinary binary. A negative number d is stored as the pattern 2n + d, which you can get by writing the absolute value in binary, inverting every bit and adding 1. For -50 in 8 bits: 50 is 0011 0010, inverted 1100 1101, plus one is 1100 1110, which equals 256 − 50 = 206 as an unsigned number.
To read a pattern whose sign bit is 1, subtract 2n from its unsigned value, or give the leading bit the weight -2n−1 and add the rest. To negate any pattern, invert it and add 1, dropping any carry out of the top bit. All the arithmetic is done with exact integers, with no rounding.
range = -2n−1 to 2n−1 − 1; negative d: pattern = 2n + d; negate = (NOT pattern + 1) mod 2n; pattern with sign bit set: value = unsigned − 2n- nbitsWidth of the number: 4, 8, 16 or 32.
- valuedecimal, binary or hex-50The decimal number to convert, or the bit pattern to read or negate.
- modechoicetoTwosDecimal to two's complement, two's complement to decimal, or negate.
- n
- bits
- Width of the number: 4, 8, 16 or 32.
- value
- decimal, binary or hex
- The decimal number to convert, or the bit pattern to read or negate.
- mode
- choice
- Decimal to two's complement, two's complement to decimal, or negate.
Using the Two's Complement Calculator
Enter what do you want to do?
Choose from Decimal to two's complement, Two's complement to decimal, Negate a bit pattern (invert, add 1).
Enter number of bits
Choose from 4 bits, 8 bits, 16 bits, 32 bits.
Enter pattern format (for the two bit-pattern modes)
Choose from Binary, Hexadecimal.
Enter value (decimal number, or the bits or hex digits)
Type the figure you already have, then press Calculate.
Read the result
Press Calculate to update the result. Until you do, the last result is dimmed and marked as out of date, so you always know which numbers belong to the values in the boxes.
A Real Worked Example
Convert -50 to 8-bit two's complement. Write 50 in binary: 0011 0010. Invert every bit: 1100 1101. Add 1: 1100 1110.
The pattern is 1100 1110, or 0xCE in hex. As an unsigned number it is 206, which is 256 − 50. The range at 8 bits is -128 to 127, so -50 fits, and the result has five 1 bits.
A positive number: 100 in 8 bits
Positive numbers are ordinary binary with leading zeros: 100 is 0110 0100 (0x64). There is nothing to invert, because the sign bit is 0.
The unsigned and signed values are both 100, and the pattern has three 1 bits.
Read 11111111 as two's complement
Choose two's complement to decimal with 8 bits and enter 11111111. The sign bit is 1, so the number is negative: -128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = -1.
The unsigned value of the same pattern is 255, which is 256 − 1. All-ones is -1 at every width.
Negate a 4-bit pattern: 1011
In 4 bits, 1011 is -5 (the sign bit gives -8, plus 2 and 1). Negate it by inverting to get 0100 and adding 1 to get 0101.
The result is +5, and the input was -5, which shows that negating twice returns the original.
Hex input: 0x8000 in 16 bits
Choose hex with 16 bits and enter 8000. In binary that is 1000 0000 0000 0000, with only the sign bit set.
Its value is -32,768, the smallest 16-bit number. As an unsigned number it is 32,768, and it has a single 1 bit.
Convert -1 to 32 bits
At 32 bits, -1 is 232 − 1 = 4,294,967,295, so the pattern is 32 ones, or 0xFFFFFFFF.
The range at 32 bits is -2,147,483,648 to 2,147,483,647, and the result has 32 ones.
The special case: negating 10000000 in 8 bits
10000000 is -128. Invert it to get 0111 1111, then add 1 to get 1000 0000, the same pattern again.
The positive counterpart, 128, does not fit in 8 bits, so -128 is its own negation. This is the one value that cannot be negated within its width.
Convert -8 to 4 bits
In 4 bits the range is -8 to 7, so -8 just fits. 8 is 1000 as unsigned, inverted is 0111, plus 1 gives 1000.
So -8 is 1000, and as an unsigned number it is 8. It is the smallest 4-bit value.
What Else to Know
What Two's Complement Is
Two's complement is the way nearly every computer stores signed integers. A number is held in a fixed number of bits, and the leading bit tells you the sign: 0 for zero and positive numbers, 1 for negative numbers.

With n bits you get 2n patterns, split evenly: half are non-negative and half are negative. That gives the range -2n−1 to 2n−1 − 1. In 8 bits it is -128 to 127, and in 32 bits it is about -2.1 billion to 2.1 billion.

The calculator takes a decimal number or a bit pattern in binary or hex, at 4, 8, 16 or 32 bits, and gives the result pattern, the hex form, the signed and unsigned values and the steps.
Decimal to Two's Complement
For a non-negative number, write ordinary binary and pad with leading zeros to the width. For 100 in 8 bits that is 0110 0100. It must be no larger than 2n−1 − 1 so the sign bit stays 0.

For a negative number, the quickest method is to write the absolute value, invert every bit and add 1. For -50: 0011 0010, inverted 1100 1101, plus 1 is 1100 1110. Another route is arithmetic: add 2n to the number, so -50 + 256 = 206, which is 1100 1110 in binary.
If the number is outside the range, it cannot be stored in that width. -200 does not fit in 8 bits, and the calculator reports the valid range rather than giving a wrong pattern.
Two's Complement to Decimal
If the leading bit is 0, read the pattern as plain binary. If it is 1, the value is negative. The easiest way to read it is to give the leading bit the weight -2n−1 and add the other bits normally.

For 1100 1110 in 8 bits: -128 + 64 + 8 + 4 + 2 = -50. Another way is to subtract 2n from the unsigned value: 206 − 256 = -50. A third way is to negate the pattern, giving the positive 50, and put a minus sign in front.
Hexadecimal input works the same way once each hex digit is expanded to four bits. 0xCE is 1100 1110, and in 16 bits 0x8000 is -32,768. The 16-bit hex table above shows more patterns.
Negating: Invert and Add One
To negate any two's complement number, invert all the bits and add 1. It works in both directions, so negating twice returns the original. 5 is 0000 0101, and -5 is 1111 1011.
The reason is arithmetic: a pattern plus its inversion is all ones, which is 2n − 1, so adding 1 more gives 2n, which is 0 in n bits. The inversion plus one is therefore the number that sums to zero with the original.
There is one exception. The most negative number, such as -128 in 8 bits, is its own negation, because +128 does not fit. The negate mode shows this case. Zero also negates to itself, as the carry falls off the end.
Why Arithmetic Just Works
The main attraction of two's complement is that the same adder handles signed and unsigned numbers. To add 5 and -3, add 0000 0101 and 1111 1101 as ordinary binary: the sum is 1 0000 0010, and dropping the carry leaves 0000 0010, which is 2.

Subtraction is addition of the negated number, so no separate subtractor is needed. There is a single zero, and comparisons and shifts work with few special cases. Older schemes such as sign-magnitude and one's complement store two zeros and need extra steps, as the comparison table shows.

Overflow still happens when the true result falls outside the range. 100 + 28 in 8 bits gives 1000 0000, which reads as -128, so a sum of two positives that comes out negative is the warning sign.
Widths, Sign Extension and Hex
To move a value to a wider width without changing it, copy the sign bit into the new high bits. The 8-bit pattern 1111 0110 (-10) becomes 1111 1111 1111 0110 in 16 bits. Padding with zeros instead would give 246, which is wrong.

Hex is a compact way to write bit patterns: each digit is four bits. 0xFF is -1 in 8 bits but 255 in 16 bits, so the width matters as much as the digits. 0x80, 0x8000 and 0x80000000 are the smallest value at 8, 16 and 32 bits.
This calculator handles whole-number integers at 4, 8, 16 and 32 bits using exact arithmetic. It does not cover fractions or floating point, which are separate formats.
Reference Tables
| Bit pattern | Hex | Unsigned value | Two's complement value |
|---|---|---|---|
| 0000 | 0 | 0 | 0 |
| 0001 | 1 | 1 | 1 |
| 0010 | 2 | 2 | 2 |
| 0011 | 3 | 3 | 3 |
| 0100 | 4 | 4 | 4 |
| 0101 | 5 | 5 | 5 |
| 0110 | 6 | 6 | 6 |
| 0111 | 7 | 7 | 7 |
| 1000 | 8 | 8 | -8 |
| 1001 | 9 | 9 | -7 |
| 1010 | A | 10 | -6 |
| 1011 | B | 11 | -5 |
| 1100 | C | 12 | -4 |
| 1101 | D | 13 | -3 |
| 1110 | E | 14 | -2 |
| 1111 | F | 15 | -1 |
| Decimal | 8-bit pattern | Hex | Notes |
|---|---|---|---|
| 127 | 0111 1111 | 0x7F | Largest value |
| 100 | 0110 0100 | 0x64 | |
| 64 | 0100 0000 | 0x40 | |
| 50 | 0011 0010 | 0x32 | |
| 10 | 0000 1010 | 0x0A | |
| 1 | 0000 0001 | 0x01 | |
| 0 | 0000 0000 | 0x00 | Only one zero |
| -1 | 1111 1111 | 0xFF | All ones |
| -2 | 1111 1110 | 0xFE | |
| -10 | 1111 0110 | 0xF6 | |
| -50 | 1100 1110 | 0xCE | |
| -64 | 1100 0000 | 0xC0 | |
| -100 | 1001 1100 | 0x9C | |
| -127 | 1000 0001 | 0x81 | |
| -128 | 1000 0000 | 0x80 | Smallest value; has no positive partner |
| Bits | Smallest value | Largest value | Distinct values | Typical type |
|---|---|---|---|---|
| 4 | -8 | 7 | 16 | Nibble (teaching) |
| 8 | -128 | 127 | 256 | int8, signed char |
| 16 | -32,768 | 32,767 | 65,536 | int16, short |
| 32 | -2,147,483,648 | 2,147,483,647 | 4,294,967,296 | int32, int |
| 64 | -9,223,372,036,854,775,808 | 9,223,372,036,854,775,807 | 18,446,744,073,709,551,616 | int64, long long |
| Step | Action | Result |
|---|---|---|
| 1 | Write 50 in binary | 0011 0010 |
| 2 | Invert every bit | 1100 1101 |
| 3 | Add 1 | 1100 1110 |
| 4 | Read as hex | 0xCE |
| 5 | Check: unsigned value | 206 = 256 − 50 |
| Bit position | 7 (sign) | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|
| Weight | -128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| 1100 1110 | -128 | 64 | 0 | 0 | 8 | 4 | 2 | 0 |
| Sum | -128 + 64 + 8 + 4 + 2 = -50 |
| Value | Sign-magnitude | One's complement | Two's complement |
|---|---|---|---|
| 7 | 0111 | 0111 | 0111 |
| 5 | 0101 | 0101 | 0101 |
| 3 | 0011 | 0011 | 0011 |
| 1 | 0001 | 0001 | 0001 |
| 0 | 0000 (and 1000) | 0000 (and 1111) | 0000 |
| -1 | 1001 | 1110 | 1111 |
| -3 | 1011 | 1100 | 1101 |
| -5 | 1101 | 1010 | 1011 |
| -7 | 1111 | 1000 | 1001 |
| Sum | Pattern 1 | Pattern 2 | Result (dropping the carry) | Decimal |
|---|---|---|---|---|
| 5 + 3 | 0000 0101 | 0000 0011 | 0000 1000 | 8 |
| 5 + (-3) | 0000 0101 | 1111 1101 | 0000 0010 | 2 |
| -5 + -3 | 1111 1011 | 1111 1101 | 1111 1000 | -8 |
| 50 + (-50) | 0011 0010 | 1100 1110 | 0000 0000 | 0 |
| 100 + 27 | 0110 0100 | 0001 1011 | 0111 1111 | 127 |
| 100 + 28 (overflow) | 0110 0100 | 0001 1100 | 1000 0000 | -128 |
| Hex | Binary | Unsigned | Signed |
|---|---|---|---|
| 0x0000 | 0000 0000 0000 0000 | 0 | 0 |
| 0x0001 | 0000 0000 0000 0001 | 1 | 1 |
| 0x007F | 0000 0000 0111 1111 | 127 | 127 |
| 0x00FF | 0000 0000 1111 1111 | 255 | 255 |
| 0x0100 | 0000 0001 0000 0000 | 256 | 256 |
| 0x7FFF | 0111 1111 1111 1111 | 32,767 | 32,767 |
| 0x8000 | 1000 0000 0000 0000 | 32,768 | -32,768 |
| 0x8001 | 1000 0000 0000 0001 | 32,769 | -32,767 |
| 0xFF00 | 1111 1111 0000 0000 | 65,280 | -256 |
| 0xFFFF | 1111 1111 1111 1111 | 65,535 | -1 |
| Hex | Signed value | Meaning |
|---|---|---|
| 0x00000000 | 0 | Zero |
| 0x00000001 | 1 | One |
| 0x7FFFFFFF | 2,147,483,647 | Largest int32 |
| 0x80000000 | -2,147,483,648 | Smallest int32 |
| 0xFFFFFFFF | -1 | Minus one |
| 0xFFFFFFFE | -2 | Minus two |
| 0xFFFF8000 | -32,768 | -32768 sign-extended from 16 bits |
| Mistake | Effect | Fix |
|---|---|---|
| Inverting without adding one | That is the one's complement, one less in size | Add 1 after inverting |
| Ignoring the bit width | 8-bit and 16-bit patterns of the same number differ | Pick the width first |
| Reading the leading 1 as part of the magnitude | A pattern that starts with 1 is negative | Use the sign bit's weight of -2n−1 |
| Expecting a positive 128 in 8 bits | 128 does not fit; the range is -128 to 127 | Use 16 bits or more |
| Forgetting to sign-extend when widening | The value changes | Copy the sign bit into the new high bits |
Frequently Asked Questions About the Two's Complement Calculator
How do you find the two's complement of a number?
Write the number in binary with the width you need, invert every bit, then add 1. For 50 in 8 bits, 0011 0010 inverts to 1100 1101, and adding 1 gives 1100 1110, which represents -50. The calculator shows each step.
How do you convert decimal to two's complement?
For a non-negative number, write its ordinary binary value and pad to the bit width. For a negative number, write the absolute value in binary, invert the bits and add 1, or compute 2n plus the number. -50 in 8 bits is 256 − 50 = 206 = 1100 1110.
How do you convert two's complement to decimal?
If the leading bit is 0, read it as an ordinary binary number. If it is 1, the number is negative: treat the leading bit as having weight -2n−1 and add the rest. 1100 1110 is -128 + 64 + 8 + 4 + 2 = -50. Or invert, add 1 and put a minus sign.
How do you negate a two's complement number?
Invert all of the bits and add 1. The same operation turns a positive number into its negative and a negative into its positive. 0000 0101 (5) becomes 1111 1011 (-5), and applying it again gives back 0000 0101. The calculator's negate mode does exactly this.
What is two's complement?
Two's complement is the standard way computers store signed integers. The leading bit is the sign bit, and an n-bit pattern represents numbers from -2n−1 to 2n−1 − 1. Negatives are found by inverting the bits of the positive and adding 1.
Why do computers use two's complement?
Addition and subtraction use the same hardware for signed and unsigned numbers, there is just one representation of zero and negation is simple. The sum of a number and its two's complement is 2n, which wraps to 0 in n bits.
What is the range of an 8-bit two's complement number?
An 8-bit signed integer runs from -128 to 127, which is 256 values. The positive end is 0111 1111 and the negative end is 1000 0000. For 4 bits the range is -8 to 7, for 16 bits it is -32,768 to 32,767 and for 32 bits it is -2,147,483,648 to 2,147,483,647.
What is the two's complement of 0?
Zero is its own two's complement. Invert 0000 0000 to get 1111 1111, add 1 and the carry falls off the end, leaving 0000 0000. There is only one zero in two's complement, which is one of its main advantages over older schemes.
What is the two's complement of -128?
In 8 bits, -128 (1000 0000) is its own negation: inverting gives 0111 1111 and adding 1 gives 1000 0000 again. The positive 128 does not fit in 8 bits. The calculator flags this case when you negate the pattern.
What is the difference between one's complement and two's complement?
One's complement just inverts the bits. Two's complement inverts and adds 1. One's complement has two zeros (0000 and 1111) and needs an end-around carry in addition. Two's complement has one zero and plain addition works. The comparison table above shows the three signed formats.
What is the difference between sign-magnitude and two's complement?
In sign-magnitude, the leading bit is the sign and the rest is the absolute value, so +3 is 0011 and -3 is 1011, and there are two zeros. In two's complement -3 is 1101, and arithmetic needs no special handling for the sign.
How do you subtract using two's complement?
To compute a - b, add a to the two's complement of b and ignore any carry out of the top bit. For 5 − 3, add 0000 0101 and 1111 1101 to get 0000 0010, which is 2. Subtraction is addition of the negative.
How do you add two's complement numbers?
Add the bit patterns as ordinary unsigned binary and drop any carry beyond the top bit. 5 + (-3) is 0000 0101 + 1111 1101 = 1 0000 0010, which is 0000 0010, or 2 after dropping the carry. The addition table above shows more cases.
What is overflow in two's complement?
Overflow happens when the true result is outside the range for the bit width, so the pattern wraps to the wrong sign. In 8 bits, 100 + 28 = 128 does not fit, and the pattern 1000 0000 reads as -128. Two positives giving a negative, or two negatives giving a positive, signals overflow.
What is the sign bit?
The sign bit is the leading, most significant bit. It is 0 for non-negative numbers and 1 for negative ones. In two's complement it has the weight -2n−1, so 1000 0000 is -128 in 8 bits, not -0. Unlike sign-magnitude, it is part of the number and not just a flag.
What is sign extension?
Sign extension widens a number to more bits by copying the sign bit into the new high bits. The 8-bit pattern 1111 0110 (-10) becomes 1111 1111 1111 0110 in 16 bits, which is still -10. Padding with zeros would give 246.
How do you convert hex to two's complement?
Convert the hex digits to binary, giving four bits per digit. If the top bit is 1, the number is negative. 0xCE is 1100 1110, so it is -50 in 8 bits. 0x8000 in 16 bits is -32,768. Choose hex input in the calculator and the bit width.
How do you convert two's complement to hex?
Find the two's complement bit pattern, group it in fours from the right and replace each group by a hex digit. -50 in 8 bits is 1100 1110, which is 0xCE. The calculator shows the bit pattern and its hex form together.
What is the two's complement of 1010?
In 4 bits, 1010 is -6. Invert it to get 0101 and add 1 to get 0110, which is +6. So the two's complement of 1010 is 0110. As unsigned numbers the same pattern is 10, and its complement mod 16 is 6.
What is the two's complement of 1011?
In 4 bits, 1011 is -5. Inverting gives 0100, and adding 1 gives 0101, which is 5. So negating 1011 gives 0101. The calculator has a negate mode that does this for any pattern at 4, 8, 16 or 32 bits, with every step shown.
What is -1 in two's complement?
-1 is all ones, whatever the width: 1111 in 4 bits, 1111 1111 in 8 bits and 0xFFFFFFFF in 32 bits. Adding 1 to it gives zero with a carry that is dropped. It is a handy pattern to recognise.
Why does the range have one more negative than positive?
There are 2n patterns. Half of them, 2n−1, have the sign bit set and so are negative, while the other half includes zero, leaving 2n−1 − 1 positives after zero takes its place. In 8 bits that gives -128 to 127, with 128 negatives and 127 positives.
How do I know how many bits I need?
Find the smallest n such that -2n−1 ≤ value ≤ 2n−1 − 1. For -50 you need 7 bits, since the 7-bit range is -64 to 63. The calculator offers 4, 8, 16 and 32 bits, and tells you when a value does not fit.
Does two's complement work for fractions?
This calculator works with whole-number integers only. Fixed-point fractions use the same invert-and-add-one idea, applied with the binary point at a fixed position, but that is a separate topic and is not covered here. Floating-point numbers use a different format altogether.
Is this the same as the 2s complement in unsigned arithmetic?
Yes. The two's complement of x in n bits is 2n − x, as an unsigned number. Whether you call the pattern signed or unsigned depends on how you read it. The calculator shows both the signed and unsigned value for every pattern.
Can the calculator check my homework answers?
Yes. It gives the final bit pattern, the hex form and the signed and unsigned values, plus the steps. Try your own value in a conversion and compare it with your working. It handles 4, 8, 16 and 32-bit widths and exact values.
How do I convert a negative decimal to binary?
Write the absolute value in binary, invert every bit and add 1, using a fixed width. For -5 in 8 bits: 5 is 0000 0101, inverted 1111 1010, plus one is 1111 1011. The calculator does this and shows the steps for 4, 8, 16 and 32 bits.
How do I convert a negative binary number to decimal?
If the leading bit is 1, subtract 2n from the unsigned value, or invert the bits, add 1 and put a minus sign in front. 1111 1011 is 251 unsigned, and 251 − 256 = -5. Choose the 'two's complement to decimal' mode in the calculator.
What is the two's complement of 5?
In 8 bits, 5 is 0000 0101. Inverting gives 1111 1010 and adding 1 gives 1111 1011, which is -5 (0xFB). In 4 bits, 5 is 0101 and its two's complement is 1011. The width decides how many leading ones appear.
What is the two's complement of 1?
In 8 bits, 1 is 0000 0001. Inverting gives 1111 1110 and adding 1 gives 1111 1111, which is -1 (0xFF). So the two's complement of 1 is all ones at any width, which is why -1 is the easiest negative number to recognise in a register or a hex dump.
Is 10000000 positive or negative?
In 8-bit two's complement it is negative: it is -128, the smallest value. The sign bit is 1, and its weight is -128, with all other bits zero. As an unsigned number the same pattern is 128, so whether it is positive or negative depends entirely on how the bits are read.
What does 0xFF mean in two's complement?
It depends on the width. In 8 bits 0xFF is -1, while in 16 bits it is 255, because the sign bit is a zero. The calculator needs the bit width and shows both the signed and unsigned values of any pattern.
How do I find the two's complement of a hex number?
Convert each hex digit to four bits, invert them all, add 1 and convert back. 0x32 is 0011 0010, inverted 1100 1101, plus 1 is 1100 1110 = 0xCE. Use the negate mode with hex input in the calculator and pick the right bit width first.
References
- [1] Wikipedia contributors. “Two's complement.” Wikipedia. Accessed 2026-10-05.
Related calculators
- Amps to Kilowatts CalculatorConvert amps to kilowatts for DC, single-phase and three-phase circuits, with power factor, kVA, kWh per day or month and an optional energy cost.Open
- Binomial Distribution CalculatorBinomial distribution calculator. Enter trials, success probability and successes for exact, at most, at least and between probabilities, plus mean.Open
- Box Plot CalculatorBox plot calculator with steps: get Q1, median, Q3, whiskers, fences and outliers from data or five numbers, with a text box and whisker plot.Open
- Boyle's Law CalculatorBoyle's law calculator: solve P1 V1 = P2 V2 for pressure or volume in atm, kPa, bar, mmHg, psi, L, mL or m3, with gauge pressure and examples.Open
