One's Complement
One's complement = flip every bit (0โ1, 1โ0). Same as bitwise NOT (~). Used in TCP/IP checksums, vintage computing, and DSP. Has two zeros: +0 and -0.
Did our AI summary help? Let us know.
TCP/IP checksum: RFC 1071 defines one's complement sum with wraparound carry. Double inversion returns original: ~~x = x. 8-bit range: -127 to +127 (two zeros: +0 and -0).
Ready to run the numbers?
Why: TCP/IP checksum uses one's complement addition. Early computers used it for signed integers before two's complement.
How: Invert each bit: 0โ1, 1โ0. Same as XOR with all 1s. Hardware: bank of NOT gates.
Run the calculator when you are ready.
Ones Complement โ Binary Number Inversion
Flip every bit (0โ1, 1โ0). Same as bitwise NOT. Used in checksums, vintage computing, and DSP.
Input Format
Input & Bit Width
For educational and informational purposes only. Verify with a qualified professional.
๐งฎ Fascinating Math Facts
TCP/IP checksum uses one's complement addition.
โ RFC 1071
Same as XOR with all 1s: x ^ 0xFF in 8-bit.
โ Digital Logic
๐ Key Takeaways
- โข The one's complement = flip all bits (0โ1, 1โ0): same as bitwise NOT (~)
- โข Negative zero problem: one's complement has two representations of zero (+0 = 00000000, -0 = 11111111)
- โข For n-bit signed integers, range is -(2^(n-1)-1) to +(2^(n-1)-1) (e.g., 8-bit: -127 to +127)
- โข Used in TCP/IP checksums, vintage computing (PDP-1), and DSP signal inversion
๐ก Did You Know?
๐ How Ones Complement Works
The one's complement of a binary number is obtained by inverting every bit. For each bit: 0 becomes 1, and 1 becomes 0. For example, 10101010 โ 01010101.
Bitwise NOT Equivalent
In programming, this is the bitwise NOT (~) operation. In C, JavaScript, Java: ~x
Signed Interpretation
For signed integers, the MSB (most significant bit) indicates sign. 0 = positive, 1 = negative. The complement of a positive number gives its negative representation.
๐ฏ Expert Tips
Checksums
TCP/IP uses one's complement sum for header checksum โ wrap-around carry is added back
vs Two's Complement
Two's = one's + 1. Two's has single zero; one's has +0 and -0. Two's is standard for modern CPUs
Bit Width
Result depends on bit width. 8-bit ~42 โ 32-bit ~42. Always specify bit width for consistency
Double Inversion
~~x = x (inverting twice returns original). Useful for bit masking in unsigned context
โ๏ธ Ones Complement vs Two's Complement
| Feature | One's Complement | Two's Complement |
|---|---|---|
| Operation | Flip all bits | Flip all bits + 1 |
| Zero representation | +0 and -0 (two zeros) | Single zero |
| 8-bit range | -127 to +127 | -128 to +127 |
| Hardware | NOT gates only | NOT + adder |
| Modern usage | Checksums, DSP | Signed integers (standard) |
โ Frequently Asked Questions
What's the difference between one's and two's complement?
One's complement = invert all bits. Two's complement = invert all bits + 1. Two's is standard for signed integers because it has a single zero and simpler arithmetic.
Where is one's complement used today?
TCP/IP checksums (RFC 1071), vintage computing, simple encryption, signal processing, and DSP signal inversion.
What is the programming equivalent?
Bitwise NOT: ~x in C/JS/Java. JavaScript uses 32-bit for bitwise ops, so ~42 = -43 in JS.
Why does one's complement have two zeros?
+0 = 00000000, -0 = 11111111. Both represent zero. Two's complement avoids this by having only one zero.
What is the signed range for n-bit one's complement?
-(2^(n-1)-1) to +(2^(n-1)-1). For 8-bit: -127 to +127. For 16-bit: -32767 to +32767.
How does TCP/IP checksum use one's complement?
The checksum is the 16-bit one's complement of the one's complement sum of all 16-bit words in the header. Wraparound carry is added back.
Can I use one's complement for negative numbers?
Yes, but two's complement is preferred. One's complement requires special handling for -0 and end-around carry in addition.
What happens when I complement twice?
Double complement returns the original: ~~x = x. Inverting all bits twice cancels out.
๐ Infographic Stats
๐ Official Sources
โ ๏ธ Disclaimer: For unsigned interpretation. Signed one's complement has different semantics. JavaScript bitwise ops use 32-bit. Always verify with official sources for checksum implementations.
Related Calculators
Binary Addition Calculator
Calculate the sum of binary numbers with step-by-step explanations. Supports binary, decimal, and hexadecimal inputs.
MathematicsBinary Multiplication Calculator
Multiply binary numbers with detailed step-by-step explanations. Supports binary, decimal, and hexadecimal inputs.
MathematicsBinary Operations Calculator
Perform binary arithmetic and logical operations with step-by-step explanations. Supports addition, subtraction, multiplication, division, and bitwise...
MathematicsBinary Division Calculator
Perform binary division operations with step-by-step solutions and visualizations.
MathematicsAND Calculator
Calculate logical AND operations between values in binary, decimal, or hexadecimal format.
MathematicsOR Calculator
Calculate logical OR operations between values in binary, decimal, or hexadecimal format.
Mathematics