How to use it
- Type the number in Number or bits. For bits, choose hexadecimal or binary under Written as.
- Choose the Width: the number of bits the computer stores, 8, 16, 32 or 64.
- Read Two's complement bits for the stored pattern, and Forms compared for the other two systems.
- If Check says the number does not fit, the bits shown are what the computer would store instead.
How a negative number is stored
A computer stores a signed integer in a fixed number of bits. In two's complement the top bit stands for −2^(n−1), and the other bits add up as usual. To write −5 in 8 bits, write 5 as 00000101, invert every bit, and add 1: 11111010 + 1 = 11111011.
−5 → 00000101 → 11111010 → 11111011 (FB in hexadecimal)
One's complement and sign-magnitude
- One's complement inverts every bit of the magnitude: −5 is 11111010.
- Sign-magnitude keeps the magnitude and sets the top bit as the sign: −5 is 10000101.
- Both have two zeros. All ones in one's complement, and a set sign bit alone in sign-magnitude, are −0.
- Two's complement has one zero and one more negative value than positive ones. It is the system most processors use for integers.
Range and overflow
With n bits the range of two's complement is −2^(n−1) to 2^(n−1) − 1: −128 to 127 for 8 bits, and −2,147,483,648 to 2,147,483,647 for 32 bits. A value outside the range wraps around: 200 needs eight bits and reads as −56, because 11001000 is −56 in two's complement.
What the tool does not cover
- Arithmetic: the tool shows how a number is stored, not the result of adding or multiplying two numbers.
- Decimal fractions and floating-point numbers, which have their own format: see the IEEE 754 converter.
- Languages that raise an error on overflow instead of wrapping. The tool shows the wrapping result, and flags it.
Worked example: −5 in 8 bits
Type −5 with Written as set to decimal and Width set to 8 bits. The pattern of two's complement is 11111011, which is FB in hexadecimal and 251 as an unsigned number.
The same −5 in the other two systems: one's complement is 11111010 and sign-magnitude is 10000101.
| System | Bits | Hex | Value |
|---|---|---|---|
| Two's complement | 1111 1011 | FB | -5 |
| One's complement | 1111 1010 | FA | -5 |
| Sign-magnitude | 1000 0101 | 85 | -5 |
| Unsigned | 1111 1011 | FB | 251 |
Frequently asked questions
Why do computers use two's complement instead of a minus sign?
A minus sign would need its own rule in every adding circuit. In two's complement, addition and subtraction work the same way for negative and positive numbers, and there is only one zero.
Why is the negative range one value larger than the positive range?
Zero takes one of the 2^n patterns, so the positive values run from 1 to 2^(n−1) − 1 and the negative values go down to −2^(n−1). In 8 bits the extra value is −128, which has no positive partner.
What does overflow mean on this page?
The number needs more bits than the width has. The page shows the bits the width would hold, and the Check line says the value does not fit. For example 128 in 8 bits holds 10000000, which reads as −128.
Why does the calculator use exact integers for 64 bits?
A JavaScript number is exact only up to 2^53, and 64-bit values go up to 2^64. The page uses BigInt, so every bit is kept and the limit −9,223,372,036,854,775,808 is shown exactly.
Does Java use two's complement for its integers?
Yes. The Java Language Specification defines its integer types in two's complement, so an int is 32 bits of two's complement and a long is 64 bits of it.
Sources
Figures and text last checked on Tuesday, November 10, 2026.