Skip to content
Math & Scientific

2S Complement Calculator

2S Complement Calculator

Enter a decimal number and a bit width to get its two’s complement binary form, one’s complement, signed range, and the full step-by-step conversion.

Computers do not store negative numbers with a little minus sign the way we write them on paper. Instead, almost every modern processor uses a system called two’s complement, where a negative number is stored as a clever rearrangement of bits that makes addition and subtraction work with the same simple circuitry. The 2S Complement Calculator above turns any decimal number into its two’s complement binary form for 8, 16, or 32 bits, and shows you the one’s complement, the signed range for that width, and every step of the conversion so you can follow the math yourself.

This page explains the whole idea in plain language: what the calculator does, how to use it, why two’s complement exists, the flip-the-bits-and-add-one method, three worked examples with full arithmetic, how to read your results, and the mistakes that trip up students most often. No prior knowledge of binary is assumed — everything is built up from scratch.

What This Calculator Does

You type in a decimal number — positive, negative, or zero — and choose a bit width: 8, 16, or 32 bits. The calculator first checks that your number actually fits in the signed range for that width (for example, −128 to 127 for 8 bits). If it fits, it produces four things: the two’s complement binary string, the one’s complement binary string, the signed range for the chosen width, and the same bit pattern read back as an unsigned number, which is a handy sanity check.

Below those headline cards, the Formula and Breakdown section walks through the conversion step by step. For a negative number you will see the magnitude converted to binary, every bit flipped, and 1 added — the famous flip-and-add-one recipe — plus a check that the result really equals 2ⁿ minus the magnitude. For a positive number the breakdown shows why no flipping is needed at all.

How to Use It

Type your decimal number into the first box. It must be a whole number — two’s complement is defined for integers, so a value like 5.5 will be rejected with an error message. Then pick 8, 16, or 32 bits from the dropdown and press Calculate.

Read the result from the top card: that is the two’s complement form, grouped in fours so it is easy to read. If you entered a number outside the signed range — say 200 with 8 bits — the calculator will not guess; it shows an error telling you the exact valid range instead. When you want a fresh start, the Reset button clears everything.

Two’s Complement in Plain English

Binary itself is simple: each position is a power of two, and you add up the positions holding a 1. The number 45, for instance, is 32 + 8 + 4 + 1, which in 8 bits is 00101101. The trouble starts with negative numbers, because bits are only ever 0 or 1 — there is no natural place for a minus sign.

Two’s complement solves this by splitting the range in half. For 8 bits there are 256 possible patterns. Half of them (starting with a 0 in the leftmost position) represent 0 through 127, and the other half (starting with a 1) represent −128 through −1. The leftmost bit becomes the sign bit: 0 means zero or positive, 1 means negative. The beautiful part is that the hardware can add these patterns with ordinary binary addition and the signs take care of themselves — 5 + (−3) gives 2 using exactly the same addition circuit as 5 + 3.

One’s complement is the close cousin you will also see: it is simply every bit flipped. Two’s complement is one’s complement plus 1. The extra 1 matters because one’s complement has an awkward “negative zero” (all 1s), while two’s complement has a single zero and one extra negative number — which is why 8 bits reach −128 but only +127.

The Method: Flip the Bits and Add One

To convert a negative decimal number −x into n-bit two’s complement, follow three steps. First, write the positive number x in binary, padded with leading zeros to fill all n bits. Second, flip every bit — every 0 becomes 1 and every 1 becomes 0 — which gives the one’s complement. Third, add 1 to that flipped pattern. The result is the two’s complement representation of −x.

There is an equivalent shortcut worth knowing: the two’s complement of −x equals 2ⁿ − x. For −45 in 8 bits, that is 256 − 45 = 211, and 211 in binary is 11010011 — the same answer the flip-and-add-one method gives. Both routes land in the same place, so you can use whichever feels clearer and check your work with the other.

For zero and positive numbers there is no flipping at all: the number is stored as its plain binary value with a 0 sign bit. That is why the calculator’s breakdown for positive inputs is much shorter — there is simply nothing to flip.

Worked Example 1: +45 in 8 Bits

Take the positive number 45 with an 8-bit width — the simplest case, and a good warm-up.

Step 1 — break 45 into powers of two: 45 = 32 + 8 + 4 + 1. Step 2 — set those bit positions: 2⁵, 2³, 2², and 2⁰ are 1, everything else is 0, giving 00101101. Step 3 — check the sign bit: the leftmost bit is 0, so the number is non-negative, and no flipping is needed. The two’s complement of +45 is therefore 0010 1101, grouped for readability.

The calculator agrees: two’s complement 0010 1101, one’s complement 0010 1101 (identical, as expected for positive numbers), signed range −128 to 127, and the unsigned reading 45. Notice how the whole left half of the 8-bit range, 00000000 through 01111111, covers 0 to 127 — the sign bit being 0 is what keeps all of these positive.

Worked Example 2: −45 in 8 Bits

Now the classic case: −45 in 8 bits. This is where flip-and-add-one earns its keep.

Step 1 — work with the magnitude: |−45| = 45. Step 2 — write 45 in 8-bit binary from the previous example: 00101101. Step 3 — flip every bit: 0→1 and 1→0 gives 11010010. That is the one’s complement of −45. Step 4 — add 1: 11010010 + 1 = 11010011. That final pattern is the two’s complement of −45.

Step 5 — sanity check with the shortcut: 2⁸ − 45 = 256 − 45 = 211. Converting 211 to binary: 211 = 128 + 64 + 16 + 2 + 1, which is 11010011. Both methods agree, so the answer is solid. The calculator shows exactly this, with the unsigned reading 211 confirming the arithmetic.

Worked Example 3: −1000 in 16 Bits

Larger numbers need wider storage. Take −1000 with a 16-bit width.

Step 1 — magnitude: |−1000| = 1000. Step 2 — break 1000 into powers of two: 1000 = 512 + 256 + 128 + 64 + 32 + 8. Step 3 — set those positions in a 16-bit field: bits 9, 8, 7, 6, 5, and 3 are 1, giving 0000 0011 1110 1000. Step 4 — flip every bit for the one’s complement: 1111 1100 0001 0111. Step 5 — add 1: 1111 1100 0001 0111 + 1 = 1111 1100 0001 1000. That is the two’s complement of −1000.

Check with the shortcut: 2¹⁶ − 1000 = 65536 − 1000 = 64536, and 64536 in binary is indeed 1111110000011000. The signed range for 16 bits is −32,768 to 32,767, so −1000 fits comfortably. Trying this same number with 8 bits would fail, because 1000 is far outside the −128 to 127 range — a good reminder to match the width to the size of your numbers.

Understanding Your Results

The top card is the headline: the two’s complement pattern, which is what a computer would actually store. The second card shows the one’s complement — the intermediate flipped-bits step. Comparing the two shows you exactly what the “+1” changed, which is the heart of the method.

The third card states the signed range for your chosen width, and it is worth memorizing the three common ones: 8 bits give −128 to 127, 16 bits give −32,768 to 32,767, and 32 bits give −2,147,483,648 to 2,147,483,647. Notice the asymmetry every time: there is always one more negative number than positive ones, because zero takes up one of the “positive-side” patterns.

The fourth card reads your bit pattern back as an unsigned number. For −45 in 8 bits it shows 211, which is not a different answer — it is the same bits interpreted without a sign. This duality is exactly why the shortcut formula works, and it is a quick way to verify a conversion by hand: compute 2ⁿ − x and compare.

Common Mistakes to Avoid

The most common mistake is forgetting to pad with leading zeros before flipping. If you write 45 as 101101 (6 bits) and flip that, you get the wrong answer — the flip must happen across the full width, so 00101101 becomes 11010010. Width matters at every step.

The second mistake is skipping the “+1” and stopping at the one’s complement. Flipping alone gives you the one’s complement, which is off by one from the two’s complement — for −45 that means 11010010 instead of the correct 11010011. Always add the 1.

Third, people misread which end is the sign bit: it is the leftmost (most significant) bit, not the rightmost. A pattern like 11010011 is negative because it starts with 1; the trailing bits tell you nothing about the sign. Fourth, watch the range: 8 bits cannot hold 200 or −200, and the calculator will tell you so — do not “fix” it by just using more bits in your head while the hardware uses 8. Finally, remember that two’s complement only applies to integers; there is no two’s complement of 3.14, which is why the calculator rejects fractional input.

Frequently Asked Questions

1. What is two’s complement?

Two’s complement is the standard way computers represent signed integers in binary. For a given bit width, half the bit patterns represent non-negative numbers and half represent negative numbers, with the leftmost bit acting as the sign bit. A negative number −x is stored as the bit pattern for 2ⁿ − x, which is equivalent to flipping all the bits of x and adding 1.

2. Why do computers use two’s complement instead of a sign bit plus magnitude?

Two’s complement lets the processor add and subtract signed numbers with a single, simple binary adder — no special sign-handling circuitry is needed. Sign-magnitude representation would need extra logic to handle the signs, and it wastes a pattern on “negative zero.” Two’s complement has exactly one zero and gives one extra negative number instead.

3. What is the difference between one’s complement and two’s complement?

One’s complement is obtained by flipping every bit of the binary number. Two’s complement is the one’s complement plus 1. For −45 in 8 bits, the one’s complement is 11010010 and the two’s complement is 11010011. The +1 eliminates the duplicate “negative zero” that one’s complement suffers from.

4. How do I convert a negative decimal number to two’s complement?

Take the absolute value, write it in binary padded to your full bit width, flip every bit, then add 1. For example, −45 in 8 bits: 45 → 00101101 → flip → 11010010 → add 1 → 11010011. Equivalently, compute 2ⁿ − x: 256 − 45 = 211 = 11010011 in binary.

5. How do I convert a two’s complement binary number back to decimal?

Look at the leftmost bit. If it is 0, the number is non-negative — just read the binary value normally. If it is 1, the number is negative: flip all the bits, add 1, convert to decimal, and put a minus sign in front. For 11010011: flip → 00101100, add 1 → 00101101 = 45, so the answer is −45.

6. What is the range of 8-bit two’s complement numbers?

From −128 to 127. In general, n-bit two’s complement covers −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1. So 16 bits cover −32,768 to 32,767, and 32 bits cover −2,147,483,648 to 2,147,483,647.

7. Why is the range asymmetric — why −128 but only +127?

With 8 bits there are 256 patterns. One pattern is used by zero, leaving 255 for nonzero numbers. Two’s complement assigns 128 patterns to negatives (−1 through −128) and 127 to positives (1 through 127). The extra negative comes from eliminating the duplicate negative zero that one’s complement has.

8. What happens if my number does not fit in the chosen bit width?

That is called overflow — the value cannot be represented, and real hardware would silently wrap around to a wrong value. This calculator refuses to guess: it shows an error with the exact valid range so you can pick a wider bit width instead.

9. What is the two’s complement of zero?

Zero is 00000000 (all zeros), and it is its own two’s complement: flipping gives 11111111, adding 1 wraps back to 00000000. Unlike one’s complement, there is only one zero in two’s complement — no confusing “negative zero.”

10. Can I use two’s complement for decimal fractions like 3.14?

No. Two’s complement is defined for integers only. Fractional numbers use completely different representations, such as fixed-point scaling or floating-point formats like IEEE 754. This calculator rejects non-integer input for exactly this reason.

11. How does subtraction work with two’s complement?

Subtraction becomes addition: a − b is computed as a + (two’s complement of b). For example, 5 − 3 becomes 5 + (−3) = 00000101 + 11111101 = 00000010 = 2, discarding the carry out of the leftmost bit. The same adder circuit handles both operations.

12. What does “reading the bits as unsigned” mean?

The same bit pattern can be interpreted two ways. The pattern 11010011 is −45 if you treat the leftmost bit as a sign (signed interpretation) but 211 if you treat all 8 bits as pure magnitude (unsigned interpretation). The calculator shows both so you can verify conversions with the 2ⁿ − x shortcut.

13. Why group the binary digits in fours?

Grouping is purely for human readability — the computer sees one continuous string of bits. Groups of four line up with hexadecimal digits (each hex digit is exactly 4 bits), so 1101 0011 is easy to read as the hex value D3. The calculator groups output this way to make long patterns like 32-bit strings manageable.

14. What is the most negative 16-bit number in binary?

−32,768, represented as 1000000000000000 — a 1 followed by fifteen 0s. This is the one value with no positive mirror image: +32,768 does not fit in 16-bit two’s complement, so negating −32,768 overflows back to itself. It is a famous edge case in programming.

15. Where is two’s complement actually used?

Everywhere integers live: CPU arithmetic units, programming language integer types (int in C, Java, and Python’s fixed-width integers in libraries like NumPy), file formats, network protocols, and embedded systems. Whenever you see a signed integer in software, two’s complement is almost certainly the representation underneath.

Final Thoughts

Two’s complement looks like a trick the first time you meet it — flip the bits, add one, and suddenly negative numbers work with plain addition. But it is really one of the most elegant ideas in computing: a single representation that makes the hardware simpler, eliminates negative zero, and squeezes one extra value out of every bit width. Use the calculator above to convert any integer, study the step-by-step breakdown until the flip-and-add-one recipe feels natural, and test yourself by converting back and forth. Once you can do −45 in 8 bits on paper without hesitation, you genuinely understand how your computer handles signed numbers.