Signed integers, made visible
Free Two’s Complement Calculator
A two’s complement calculator converts signed integers between decimal, binary and hex for a fixed bit width. Explore the bits, follow the invert-and-add steps, and check addition or subtraction without losing 64-bit precision.
Free · No signup · Calculations stay in your browser
Signed range: -128 to 127
Decimal accepts a signed whole number. Binary and hex are unsigned bit patterns interpreted at the selected width; shorter words are padded with zeros. Optional 0b / 0x prefixes are accepted.
Your 8-bit word
- Signed decimal
- -5
- Unsigned decimal
- 251
- Two’s complement binary
- 11111011
- Hex word
- FB
Click a bit to flip it
The leftmost bit is the sign bit. A 1 there means the signed value is negative. Positions count from 0 on the right.
Step by step
- 1. Write the magnitude and pad to 8 bits:
00000101 - 2. Invert every bit:
11111010 - 3. Add 1 to get the two’s complement word:
11111011 - To decode it, subtract 2^8 from the unsigned word: 251 − 256 = -5.
The same signed number in other encodings
- One’s complement
- 11111010
- Sign-magnitude
- 10000101
These are alternative encodings of the same value, not alternate interpretations of the word above. One’s complement and sign-magnitude each use a negative-zero pattern, so their most negative value is one closer to zero.
Two’s complement questions
How do you calculate two’s complement?
For a negative integer, write its absolute value in binary, pad to the chosen width, invert every bit, then add 1. For -5 at 8 bits: 00000101 becomes 11111010, then 11111011.
What is 11111111 in two’s complement?
At 8 bits, 11111111 represents -1 in two’s complement and 255 as an unsigned integer. Width matters: the same digits padded to 16 bits with leading zeros represent positive 255.
What range can an n-bit signed integer hold?
An n-bit two’s complement integer ranges from -2^(n-1) to 2^(n-1)-1. At 8 bits this is -128 through 127; at 64 bits it is -9223372036854775808 through 9223372036854775807.
Are carry and signed overflow the same?
No. Signed overflow means the mathematical result is outside the signed range. Carry is a bit beyond the word in unsigned addition. At 8 bits, 127 + 1 overflows without carry; -1 + 1 has carry without signed overflow. For subtraction computed as A + NOT(B) + 1, carry means no unsigned borrow.
Does this calculator keep 64-bit values exact or upload my inputs?
It uses JavaScript BigInt for integer arithmetic, so all 64 bits stay exact. Calculations run in your browser without sending your entered values to a calculator API or saving them.
Implementation reference: MDN: BigInt.asIntN and signed two’s complement.
Related free tools
Need help shipping your software?
Meet the AI developers behind these free tools.
Explore Elite Coders AI →