Two's Complement Calculator - CalcVenue

Two's Complement Calculator

Convert a decimal number to its two's complement binary representation, or convert a two's complement binary number back to decimal. Pick the bit length, enter your number, and see the binary pattern, its decimal value, and the two's complement (the opposite number).

Bit length
Decimal

Enter a whole number between −128 and 127.

Two's Complement Calculator: Convert Decimal and Binary

The two's complement calculator is a fast, two-way converter for signed binary numbers. Give it a decimal number and it returns the two's complement binary pattern a computer would store; give it a two's complement binary number and it returns the decimal value that pattern represents. You choose the bit length — 4, 8, 12, 16, 32, 64, or a custom width — and the calculator handles the sign, the wrap-around, and the bit grouping for you. It is built for computer science students, programmers, digital-electronics learners, and anyone who needs to see exactly how negative numbers live inside a computer.

This page explains what two's complement is, why computers use it, the exact steps to convert in both directions, worked examples you can reproduce, and answers to the questions people ask most. By the end you will be able to convert signed binary by hand — and use the calculator whenever you want an instant, error-free answer.

What Is Two's Complement?

Two's complement is the standard way computers represent signed (positive and negative) integers in binary. In an unsigned binary number every bit simply adds a power of two, so you can only represent zero and positive numbers. Two's complement solves the problem of negatives by giving the leftmost bit — the most significant bit — a negative weight. In an 8-bit number the leftmost bit is worth −128 instead of +128, while the remaining bits keep their normal positive values. This single change lets a fixed number of bits represent both positive and negative values, and — crucially — lets the computer add and subtract them using exactly the same circuitry it uses for unsigned numbers.

Why Computers Use Two's Complement

There are several ways to represent negative numbers in binary — sign-and-magnitude and one's complement among them — but two's complement won out for good reasons. First, it has only one representation of zero, whereas sign-and-magnitude and one's complement both have a "positive zero" and a "negative zero," wasting a bit pattern and complicating comparisons. Second, addition and subtraction just work: you add two's complement numbers with the ordinary binary addition algorithm and, ignoring any carry out of the top bit, the result is correct whether the operands are positive or negative. Third, subtracting is simply adding the two's complement of the number, so the hardware needs an adder and a bit-flipper, nothing more. This elegance is why virtually every modern processor stores signed integers in two's complement form.

The Range of Values for N Bits

With N bits in two's complement, you can represent every whole number from −2N−1 up to 2N−1−1. The range is slightly lopsided: there is one more negative value than positive, because zero takes up one of the "positive" slots. For the common widths this gives:

BitsMinimumMaximum
4−87
8−128127
16−32,76832,767
32−2,147,483,6482,147,483,647
64−9,223,372,036,854,775,8089,223,372,036,854,775,807

If you enter a decimal number outside the range for your chosen bit length, the calculator will tell you, because that value cannot be stored without more bits.

How to Convert Decimal to Two's Complement

Converting a decimal number to two's complement binary takes just a few steps:

  1. Positive numbers are written as ordinary binary, padded with leading zeros to fill the chosen number of bits. For example, in 8 bits, 16 becomes 0001 0000.
  2. Negative numbers start from the binary of the positive value, then you invert every bit (change each 0 to 1 and each 1 to 0) and add 1. For −16: start with 0001 0000, invert to 1110 1111, add 1 to get 1111 0000.

An equivalent shortcut for negatives is to compute 2N minus the absolute value and write that in binary: for 8 bits, 256 − 16 = 240 = 1111 0000. Both methods give the same answer, and that is exactly what the calculator does.

How to Convert Two's Complement to Decimal

Reading a two's complement binary number back into decimal is just as systematic. The easiest method is to give the leading bit a negative weight and add up the columns:

  1. Write out the place values. In 8 bits they are, from left to right, −128, 64, 32, 16, 8, 4, 2, 1.
  2. Add the values wherever there is a 1. For 1011 1011: −128 + 32 + 16 + 8 + 2 + 1 = −69.

An alternative is to check the leading bit: if it is 0 the number is positive and you read it as normal binary; if it is 1, invert all the bits, add 1, convert to decimal, and put a minus sign in front. Both roads lead to the same value — and the calculator shows the result instantly.

Worked Example 1: Decimal −16 in 8 Bits

Enter −16 with an 8-bit length. The calculator inverts the binary of 16 and adds 1, giving the two's complement representation 1111 0000. It also shows the two's complement of that pattern, 0001 0000, which is the representation of +16 — the "opposite" number. So in 8-bit two's complement, −16 is stored as 11110000. These are the calculator's default values, so you can press Convert to see them and then try your own.

Worked Example 2: Binary 10111011 to Decimal

Switch to the Binary → Decimal tab and enter 10111011 with an 8-bit length. Because the leading bit is 1, the number is negative. Giving that bit a weight of −128 and summing the rest gives −128 + 32 + 16 + 8 + 2 + 1 = −69. The calculator also reports the complement 0100 0101, which is +69. This confirms that the bit pattern 10111011, interpreted as an 8-bit signed number, equals −69.

How to Use the Two's Complement Calculator

  1. Choose the bit length from the dropdown, or pick "Other" and type a custom width.
  2. Select a direction. Use the "Decimal → Binary" tab to encode a decimal number, or "Binary → Decimal" to decode a bit pattern.
  3. Enter your number and press Convert.
  4. Read the results — the binary representation, the decimal value, and the two's complement (the opposite number), all grouped into four-bit nibbles for readability.

Two's Complement vs. One's Complement and Sign-Magnitude

It helps to see how two's complement compares with the older schemes it replaced. In sign-and-magnitude, the leading bit is just a sign flag and the rest is the plain magnitude, so −5 and +5 differ only in that first bit; the drawback is two zeros and awkward arithmetic. In one's complement, a negative number is formed by inverting all the bits of the positive; it also suffers from two zeros and needs an "end-around carry" when adding. Two's complement takes one's complement and adds 1, which removes the negative zero and makes addition seamless. The trade-off — a single extra negative value and a slightly less obvious negation step — is well worth it, which is why two's complement is the universal choice today.

Overflow: When the Result Won't Fit

Because a fixed number of bits can only hold a limited range, arithmetic can overflow — produce a result too large or too small to represent. In two's complement, overflow happens when you add two numbers of the same sign and get a result of the opposite sign: adding two positives and getting a "negative," or two negatives and getting a "positive." For example, in 8 bits, 127 + 1 wraps around to −128. Processors detect this with an overflow flag, and programmers must watch for it when a calculation might exceed the type's range. Understanding the range for each bit width — which this calculator makes explicit — is the first step to avoiding overflow bugs.

Where Two's Complement Is Used

Two's complement is everywhere in computing, even though most programmers rarely see the raw bits. Every signed integer type in languages like C, C++, Java, Rust, and Go is stored in two's complement, so the behavior of negative numbers, bit shifts, and overflow all follow its rules. It underlies assembly-language arithmetic, digital-signal processing, network protocols that carry signed fields, checksums, and the design of arithmetic-logic units in CPUs. Anyone studying computer architecture, embedded systems, or low-level programming needs a solid grasp of it — and being able to convert quickly, by hand or with a tool, is a core skill.

Signed vs. Unsigned Binary

The very same bit pattern can mean two completely different numbers depending on whether it is read as signed or unsigned. Take the 8-bit pattern 1111 0000. Interpreted as an unsigned number, every bit has a positive weight, so it equals 128 + 64 + 32 + 16 = 240. Interpreted as a two's complement signed number, the leading bit carries a weight of −128, giving −128 + 64 + 32 + 16 = −16. Neither reading is "more correct" — the meaning is decided entirely by the type you assign to the data. This is exactly why programming languages distinguish signed and unsigned integer types: the bits in memory are identical, but the rules for reading them, comparing them, and shifting them differ. Understanding this dual interpretation is one of the biggest "aha" moments in learning how computers store numbers, and it is why a two's complement calculator always asks you to fix the bit length before it can give a definite answer.

The Most Negative Number and Its Quirk

Every bit width has one value that behaves oddly: the most negative number, −2N−1. In 8 bits that is −128, stored as 1000 0000. The quirk is that you cannot negate it within the same width. If you try to take its two's complement — invert the bits to 0111 1111 and add 1 — you get 1000 0000 right back, which is still −128, not +128, because +128 does not fit in 8 bits. This asymmetry is a direct consequence of there being one more negative value than positive value in the range. It matters in real code: taking the absolute value of the most negative integer can overflow and quietly return a negative result, a classic source of subtle bugs. The calculator represents this value correctly, and seeing it helps explain why the range is −2N−1 to 2N−1−1 rather than a symmetric span.

Bit Grouping and Readability

Long strings of ones and zeros are hard for people to read, so this calculator groups the bits into nibbles — blocks of four — separated by spaces, exactly as engineers do by hand. A nibble is convenient because four bits correspond neatly to a single hexadecimal digit, which is why hexadecimal is such a popular shorthand for binary. For example, the 8-bit value 1111 0000 is two nibbles, 1111 and 0000, which translate to the hex digits F and 0, giving 0xF0. Grouping does not change the value in any way; it is purely a visual aid that makes it far easier to spot patterns, compare two numbers, or transcribe a result without losing your place. When you copy a result from the calculator, you can simply remove the spaces to get the raw bit string your code or hardware expects.

Frequently Asked Questions

How do you find the two's complement of a binary number?

Invert every bit (0 becomes 1 and 1 becomes 0), then add 1 to the result. For example, the two's complement of 00010000 is 11110000.

What is the two's complement of a negative number?

Taking the two's complement negates the number, so the two's complement of a negative value is the corresponding positive value's bit pattern. The operation turns −16 into +16 and vice versa.

Why is the leftmost bit negative in two's complement?

Giving the most significant bit a negative weight (for example −128 in 8 bits) is what lets a fixed number of bits represent negatives while keeping ordinary binary addition correct.

What is the range of an 8-bit two's complement number?

An 8-bit two's complement number can represent any integer from −128 to 127, that is from −2⁷ to 2⁷−1.

How is subtraction done in two's complement?

To subtract, you add the two's complement of the number being subtracted. This lets a computer use the same adder circuit for both addition and subtraction.

Does two's complement have a negative zero?

No. Unlike sign-and-magnitude and one's complement, two's complement has a single representation of zero, which is one of its main advantages.

Disclaimer

This Two's Complement Calculator is provided for general educational purposes. It uses the standard two's complement definition for signed binary integers. Results assume the bit length you select; the same bit pattern can represent different values under a different width or a different signed-number scheme.