Skip to content
FiftyCalc Free calculators for all 50 states

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

Sample figures

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.

One's Complement Calculator

Whole number (0 to 2 to the power of the bit width, minus 1): enter 0 or more. Prefilled example: 5.

Bit width

Bit width: choose 8 bits, 16 bits or 32 bits. Prefilled example: 8 bits.

How to use this calculator

Fill in the fields in this order; each step takes you to its field.

  1. Whole number (0 to 2 to the power of the bit width, minus 1): enter 0 or more.
  2. Bit width: choose 8 bits, 16 bits or 32 bits.
  3. 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

  1. C={2w−1−nif n≥0 and n<2w and n=floor⁡(n)−1otherwise
Symbols used in the formula
SymbolMeaning
nWhole number (0 to 2 to the power of the bit width, minus 1)
wBit width (8: 8 bits; 16: 16 bits; 32: 32 bits)
COne'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 width8 bits
Value of the input read as a signed one's complement number5
Two's complement (one's complement + 1)251
  1. C=28−1−5=250

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.

Related calculators