Math
Two's Complement Calculator
Two's complement is how every modern computer stores negative whole numbers.
Enter a decimal to see its two's complement pattern at your chosen width, with the invert-and-add-1 steps, or enter a bit pattern to decode it. The calculator checks the signed range and reports overflow instead of wrapping silently.
A whole number, positive or negative. It must fit the signed range of the chosen width.
How many bits the register holds. 8-bit is a byte; 32-bit and 64-bit match most programming languages.
Try an example
Result
Result
—
- Hexadecimal
- —
- Unsigned reading
- —
- Signed range
- —
Student quick launch
Grade planning, algebra checks, and formulas students reach for most.
Study path
Use this calculator with
Follow these when you want the formula behind the answer, a short lesson, or nearby tools in the same topic.
What the two's complement calculator solves
In an n-bit register, two's complement represents values from −2^(n−1) to 2^(n−1) − 1. The leftmost bit acts as a sign bit worth −2^(n−1) instead of +2^(n−1). The big advantage is that addition and subtraction work with the same circuit as unsigned arithmetic. This calculator converts in both directions and shows why the bit pattern is what it is.
Signed ranges by width
| Width | Minimum | Maximum | Unsigned maximum |
|---|---|---|---|
| 4-bit | −8 | 7 | 15 |
| 8-bit | −128 | 127 | 255 |
| 16-bit | −32,768 | 32,767 | 65,535 |
| 32-bit | −2,147,483,648 | 2,147,483,647 | 4,294,967,295 |
| 64-bit | −9,223,372,036,854,775,808 | 9,223,372,036,854,775,807 | 18,446,744,073,709,551,615 |
How to use it
- Pick the direction: decimal to two's complement, or bit pattern to decimal.
- Choose the register width. 8-bit is the classic classroom size; 32-bit matches int in most languages.
- Enter the decimal or the full bit pattern. For patterns, type every bit so the sign bit lands in the right place.
- Follow the bit rows: The length or size of a vector, ignoring which way it points., inverted, then add 1. The blue row is the answer.
How to read the answer
A leading 1 means negative. The unsigned reading shows what the same bits mean if you ignore the sign convention, which explains why −1 and 255 look identical in a byte. Hex is shown because debuggers print registers in hex: −5 in 8 bits is FB.
Common mistakes and edge cases
- Forgetting to add 1 after inverting. Inverting alone gives one's complement, which is off by one.
- Using too few bits. −5 needs at least 4 bits (1011); at 8 bits it is 11111011. The width changes the pattern.
- Overflow: 128 does not fit in a signed byte (max 127). The calculator refuses instead of showing −128.
- −128 is valid in 8 bits (10000000) even though +128 is not; the range is asymmetric.
- Decoding a short pattern: 1011 at 8 bits is padded to 00001011 = 11, not −5. Type all 8 bits for negatives.
Worked examples
Negative to 8-bit
−5 at 8 bits
Result
11111011
Positive to 8-bit
5 at 8 bits
Result
00000101
Minimum value
−128 at 8 bits
Result
10000000
Zero
0 at 8 bits
Result
00000000
Decode a negative pattern
11111011 as 8-bit
Result
-5
Decode −1 at 16 bits
1111111111111111
Result
-1
Large 32-bit negative
−2,147,483,648
Result
10000000000000000000000000000000
Overflow
128 at 8 bits
Result
—
Invalid bit
1012 as a pattern
Result
—
Frequently asked questions
How do you find the two's complement of a number?+
Write the magnitude in the register width, flip every bit (0↔1), and add 1. For −5 in 8 bits: 00000101 → 11111010 → 11111011.
How do you convert two's complement back to decimal?+
If the leftmost bit is 0, read it as ordinary binary. If it is 1, invert the bits, add 1, read the magnitude, and put a minus sign in front. 11111011 → 00000100 → 00000101 = 5, so the value is −5.
Why is the range −128 to 127 and not −127 to 127?+
There are 256 patterns in a byte. Zero uses one, 127 positives use 127, leaving 128 patterns for negatives, so the most negative value is −128 (10000000).
What is two's complement overflow?+
Trying to store a value outside the signed range. 127 + 1 in 8-bit arithmetic wraps to −128 because the bits become 10000000. This calculator flags values that do not fit rather than wrapping.
Why do computers use two's complement instead of a sign bit?+
With two's complement, the same adder circuit handles positive and negative numbers, subtraction is just adding the complement, and there is only one zero. Sign-magnitude and one's complement both have a separate negative zero.
What is −1 in two's complement?+
All ones: 11111111 in 8 bits, FFFF in 16-bit hex, FFFFFFFF in 32-bit hex. Adding 1 rolls over to zero.
About this calculator
- Written by
- mathcheck editorial team
- Last reviewed
- September 4, 2026
Method
- Uses the values entered by the user and stable formulas documented on the page.
Related calculators
One's Complement Calculator
Find the one's complement of a binary pattern by flipping every bit, encode a signed decimal in one's complement at a chosen width, or decode a pattern, with the two's complement shown for comparison.
Binary to Decimal Converter
Convert binary to decimal with the positional-weight table (bit × 2^n), fractional bits after the binary point, and an option to read the bits as a signed two's complement number.
Decimal to Binary Converter
Convert decimal to binary with the repeated-division steps, fractional parts by repeated multiplication (0.625 → 0.101), repeating-fraction detection, and negatives as a sign or two's complement.
Bitwise Calculator
AND, OR, XOR, NOT, NAND, and NOR on binary, decimal, octal, or hex inputs at 4 to 64 bits, with an aligned bit grid, a bit-by-bit truth table, and the result in every base.
Bit Shift Calculator
Left, logical right, and arithmetic right shifts at 4 to 64 bits with the before/after bit rows, bits shifted out, overflow detection, and the ×2^n or ÷2^n meaning of the shift.
Binary Subtraction Calculator
Subtract binary numbers with each borrow shown in an aligned column grid, negative answers handled, and the difference checked in decimal, hex, and octal.
Last updated: September 4, 2026