Guide
Two’s complement: how computers store negative integers
Signed integers need a rule for the negative side, and almost every processor uses the same one: two’s complement. The pattern for −x is what you get when you subtract x from 2 to the power n, where n is the number of bits. It has two useful features. Addition and subtraction use the same circuit whatever the signs, and there is only one zero. This page converts in both directions and shows how.
The invert-and-add-one rule
To find the pattern of a negative number, write its size in binary using the chosen width, flip every bit, and add one. For −5 in 8 bits the size is 00000101, the inverted bits are 11111010, and adding one gives 11111011, which is hexadecimal FB. To read a pattern back, check the top bit: if it is 0 the number is positive and you read it as ordinary binary; if it is 1 you invert, add one and negate.
Range and the extra negative number
An n-bit signed integer runs from −2^(n−1) to 2^(n−1) − 1. For 8 bits that is −128 to 127; for 16 bits −32,768 to 32,767; for 32 bits −2,147,483,648 to 2,147,483,647. The page prints the smallest and largest values for the width you picked. If a number lies outside the range, it says so and does not wrap around, because silent overflow is exactly the kind of mistake people use a calculator to catch.
Input types
Choose whether your input is a signed decimal number, a binary pattern or a hexadecimal pattern. Decimal input is turned into bits for the chosen width. Binary and hex input are read as patterns of that width and shown as signed and unsigned numbers. A pattern shorter than the width is padded with zeros on the left, so write the sign bit explicitly when you mean a negative value.
Other forms shown
Beside the answer, the page lists the one’s complement, where every bit is simply flipped, and sign-magnitude, where the top bit is a sign and the rest is the size. These older schemes have two zeros and need extra care in arithmetic, which is why two’s complement won. The value −128 has no sign-magnitude form in 8 bits, and the page marks it as such.
A worked example
The Sample button loads −42 at 8 bits. The size 42 is 00101010, the inverted bits are 11010101, and adding one gives 11010110. In hexadecimal that is D6, and read as an unsigned byte it is 214, which equals 256 − 42. The one’s complement is 11010101 and the sign-magnitude form is 10101010. The range line reads −128 to 127, so the value fits. In 16 bits the same number becomes 1111111111010110, showing how sign extension copies the top bit.
Limits
Only fixed widths of 4, 8, 16, 32, 64 and 128 bits are offered, and the arithmetic is done with big integers, so there is no rounding. The page does not simulate overflow flags or arithmetic operations, and it does not know what type your variable has. When you compare with a program’s output, check that the program uses the same width and signedness. For bit patterns of floating-point numbers use the IEEE 754 converter instead.
Related tools
- Binary to Decimal reads bits as an unsigned number.
- Decimal to Binary shows the division method for positive numbers.
- IEEE 754 Converter covers floating-point storage.
- Bitmask Calculator combines and tests bits with AND, OR and XOR.
Checked against the current version of the Two’s Complement Calculator on .

