One's Complement Calculator
Test cases replayed : 3 of 3 match · Methodology · No outside source listed
Enter a whole number and a word size to flip all its bits.
Result
One's complement (bits flipped)
Value of the input read as a signed one's complement number
- Two's complement (one's complement + 1)
Estimate for planning only, not tax, legal, financial or medical advice. This calculator uses the method explained on this page.
This browser did not allow copying. The sentence is in the box below, already selected: copy it with your keyboard or the menu.
How to use this calculator
Fill in the fields in this order; each step takes you to its field.
- Whole number (0 to 2 to the power of the bit width, minus 1): enter 0 or more.
- Bit width: choose 8 bits, 16 bits or 32 bits.
- Read the result: One's complement (bits flipped); the panel also shows Value of the input read as a signed one's complement number and Two's complement (one's complement + 1).
How this calculator works
The one's complement flips every bit of a w-bit word: 0 becomes 1 and 1 becomes 0. Numerically that is (2ʷ − 1) − n.
In one's complement signed notation, a word whose top bit is 1 stands for minus the complement of the word, so it has both +0 and −0. Two's complement, used by today's processors, adds 1 to the one's complement and has a single zero.
The formula
| Symbol | Meaning |
|---|---|
| Whole number (0 to 2 to the power of the bit width, minus 1) | |
| Bit width (8: 8 bits; 16: 16 bits; 32: 32 bits) | |
| One's complement (bits flipped) | |
floor(x) | the largest whole number not above x. |
Worked example
| Whole number (0 to 2 to the power of the bit width, minus 1) | 5 |
|---|---|
| Bit width | 8 bits |
| Value of the input read as a signed one's complement number | 5 |
|---|---|
| Two's complement (one's complement + 1) | 251 |
One's complement (bits flipped) 250
Each step uses the unrounded value of the step before it; figures on this page are rounded for display.
Frequently asked questions
What is the one's complement of 5 on 8 bits?
5 = 00000101, so the complement is 11111010 = 250. The two's complement is 251.
What does 250 mean as an 8-bit one's complement number?
Its top bit is 1, so it is negative: minus the complement of 11111010, which is −5.