Two’s Complement Converter
Turn a signed number into its two’s complement bits, or read a bit pattern back. Works at 8, 16, 32 or 64 bits, with the invert-and-add-one working and the unsigned reading of the same bits.
How to Use
- Choose whether you are entering a signed value (like −42) or a bit pattern (like 0xD6 or 11010110).
- Pick the width: 8, 16, 32 or 64 bits, the size of the integer type.
- Type the number. A 0x or 0b prefix is always read as a bit pattern.
- Read the signed value, the unsigned reading of the same bits, the hex and the binary; the drawing marks the sign bit.
- If a value is too big for the width, it is shown wrapped, the way a C or Java cast stores it.
Worked Example
−42 as an 8-bit signed integer. Write 42 in 8 bits: 0010 1010. Invert every bit: 1101 0101. Add 1: 1101 0110, which is 0xD6. Check it by giving the top bit a weight of −128: −128 + 64 + 16 + 4 + 2 = −42. Read as an unsigned byte, the same bits are 128 + 64 + 16 + 4 + 2 = 214, which is 256 − 42.
0xFFFFFFF6 as a 32-bit int. The top bit is 1, so it is negative. Invert: 0x00000009; add 1: 0x0000000A = 10. The value is −10. Unsigned, the same bits are 4,294,967,286.
The common mistake: just setting the sign bit. Writing 42 and turning on the top bit gives 1010 1010. That is how sign-magnitude stores −42, but in two’s complement it means −128 + 32 + 8 + 2 = −86.
Show Work
Formulas
Why Two’s Complement Won
Early computers tried several ways to store negative numbers. Sign-magnitude, a sign bit in front of the size, is how we write on paper, but it needs a separate subtractor and has two zeros. Ones’ complement, used by the CDC 6600 and the UNIVAC 1100 series, flips every bit to negate, but still has a +0 and a −0 and needs an “end-around carry” when adding.
Two’s complement, described by John von Neumann in his 1945 report on the EDVAC, removes both problems: one zero, and ordinary binary addition gives the right answer for any mix of signs. IBM’s System/360 used it in 1964 and it became universal; the C++20 and C23 standards finally made it the only representation allowed for signed integers.
About This Calculator
This converter turns a signed integer into its two’s complement bit pattern at 8, 16, 32 or 64 bits, or reads a hex or binary pattern back as a signed and an unsigned number. It shows the invert-and-add-one steps, marks the sign bit, gives the range of the width, and wraps out-of-range values the way a cast does, using exact whole-number arithmetic even at 64 bits.
Everything runs in your browser; nothing is sent anywhere. For sign-magnitude, ones’ complement and offset binary side by side, use the signed representations tool.
Related calculators: Signed Number Representations, Bitwise Calculator, and Number Base Converter.
Frequently Asked Questions
How do I find the two's complement of a number?
Write the positive number in binary at the full width, invert every bit, then add 1. For −42 in 8 bits: 42 is 00101010, inverted 11010101, plus 1 is 11010110. Check it by giving the top bit a weight of −128: −128 + 64 + 16 + 4 + 2 = −42.
How do I read a two's complement number?
If the top bit is 0, it is an ordinary binary number. If it is 1, the number is negative: count the top bit as −2ⁿ⁻¹ and add the rest normally, or invert all the bits, add 1 and put a minus sign in front. 0xFFFFFFF6 as a 32-bit int is −10.
What is the range of a signed integer?
With n bits, from −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1: −128 to 127 for 8 bits, −32,768 to 32,767 for 16, −2,147,483,648 to 2,147,483,647 for 32. There is one more negative number than positive, so negating the most negative value overflows back to itself.
What happens when a value does not fit?
Only the lowest n bits are kept, so the value wraps around. 200 stored in a signed byte becomes 200 − 256 = −56; 128 becomes −128. In C, converting an out-of-range value to a signed type is implementation-defined, but every common compiler wraps like this, and Java and C# define it to.
Why do computers use two's complement?
Because the same adder works for signed and unsigned numbers: adding the bit patterns gives the right answer either way, with no special case for negative numbers. It also has only one zero, unlike sign-magnitude and ones’ complement, which both have a +0 and a −0.
How do I use the Two’s Complement Converter?
Just type or paste your value. The answer shows up right away — there is no button to press. Change anything and it updates by itself.
Do I need to install or sign up for anything?
Not at all — it runs in the browser with nothing to install and no account. After it loads once, it even works without an internet connection.
Is my information private?
Yes. Everything happens in your browser. Nothing you type is sent to a server or saved anywhere.
Common Use Cases
Reading registers
0xFFFFFFF6 in a 32-bit register is −10, not 4,294,967,286.
Overflow bugs
200 stored in an int8_t wraps to −56; 128 wraps to −128.
Homework
−42 at 8 bits: 00101010 → 11010101 → 11010110, with every step shown.
Sensor data
A 16-bit reading of 0xFF38 is −200, for example −2.00 °C at 0.01 °C per count.
Last updated: