One's Complement Calculator
Invert every bit of a fixed width binary number.
What it does
One's complement is an old method for representing signed integers. To negate a value, every bit is flipped. The width must be fixed, because the pattern of leading zeros determines the result.
UC Berkeley CS 61C course notes introduce integer representations and explain how bit strings encode signed and unsigned values.
North Carolina State University notes on integer arithmetic compare negation methods. Flipping all bits is simple because no bit depends on another and there are no carries, but one's complement has two zeros and needs an end around carry in addition.
This tool takes a nonnegative integer, writes it with a chosen bit width, flips every bit and reports the resulting pattern and its unsigned decimal interpretation.
Two's complement, which flips the bits and then adds one, replaced one's complement in most modern hardware.
How to use
- Enter an integer from 0 to 255.
- Choose 8 or 16 bit width.
- Read the complemented bit pattern.
- Check the unsigned decimal value of that pattern.
- Try 5 in 8 bits to get 11111010.
- Compare with two's complement on the same input.
Formula
- N
- Fixed number of bits, here 8 or 16.
- bit
- A single binary digit.
- NOT
- Logical inversion of a bit.
- end around carry
- Carry handling needed for one's complement addition.
The engine pads the input to the chosen width before flipping. It rejects values outside the range that fits the width.
Worked example
Example: 5 in eight bits
Input 5 with 8 bit width.
- Five in eight bit binary is 00000101.
- Flipping each bit gives 11111010.
- As an unsigned 8 bit value, 11111010 is 250.
- The tool reports complement 11111010 and unsigned value 250.
- In signed one's complement that pattern would represent minus five.
- Two's complement would give 11111011, or 251 unsigned.
Reference table
| Value | Binary | One's complement | Unsigned |
|---|---|---|---|
| 0 | 00000000 | 11111111 | 255 |
| 1 | 00000001 | 11111110 | 254 |
| 5 | 00000101 | 11111010 | 250 |
| 255 | 11111111 | 00000000 | 0 |
Limits
- The tool supports 8 and 16 bit widths only.
- Inputs are limited to 255 even in 16 bit mode.
- It reports the unsigned interpretation of the complemented pattern.
- It does not perform one's complement arithmetic.
Common mistakes
- Forgetting to pad with leading zeros before flipping.
- Confusing one's complement with two's complement.
- Expecting a single representation of zero.
- Entering a negative number, which the tool rejects.
- Reading the unsigned value as the signed value without noting the difference.
Try it yourself
Quick checks. Answers sit tucked under each question.
What is the 8 bit one's complement of 5?
11111010, which is 250 unsigned.
How does two's complement differ?
It adds one after flipping all bits.
How many zeros does one's complement have?
Two, positive zero and negative zero.
Questions
What is one's complement?
A signed integer representation formed by flipping every bit.
Why does width matter?
Leading zeros are part of the representation and get flipped too.
Why was it replaced?
Two's complement has a single zero and simpler arithmetic.
What is end around carry?
A carry correction needed when adding one's complement numbers.
Does the tool do arithmetic?
No. It only forms the complement.
What widths are supported?
8 and 16 bits.
Sources
- UC Berkeley CS 61C, Integer Representations
- North Carolina State University, Integer Arithmetic notes