Ones Complement Calculator
Free Ones complement Calculator for exponents & logarithms. Enter values to get step-by-step solutions with formulas and graphs.
Reviewed by Manoj Kumar, Mathematics Educator
Formula
Ones Complement = Flip all bits (0 to 1, 1 to 0)
The ones complement of a binary number is obtained by inverting every bit. For an n-bit number N, the ones complement equals (2^n - 1) - N. The original plus its ones complement always equals a string of all 1s (2^n - 1).
Worked Examples
Example 1: 8-Bit Ones Complement of 42
Problem:Find the ones complement of decimal 42 using 8-bit representation.
Solution:Step 1: Convert 42 to 8-bit binary\n42 = 00101010\n\nStep 2: Flip all bits (0 becomes 1, 1 becomes 0)\n00101010 -> 11010101\n\nStep 3: Verify\nOriginal + Complement = 00101010 + 11010101 = 11111111 (all ones)\n\nUnsigned decimal: 11010101 = 213\nSigned interpretation: -42
Result:Ones complement of 42 = 11010101 (unsigned 213, signed -42)
Example 2: 16-Bit Ones Complement for Checksum
Problem:Compute the ones complement of the 16-bit value 0xAB12 for an IP checksum calculation.
Solution:Step 1: Convert 0xAB12 to binary\n0xAB12 = 1010101100010010\n\nStep 2: Flip all bits\n1010101100010010 -> 0101010011101101\n\nStep 3: Convert back\n0101010011101101 = 0x54ED (decimal 21,741)\n\nVerify: 0xAB12 + 0x54ED = 0xFFFF (all ones)
Result:Ones complement of 0xAB12 = 0x54ED
Frequently Asked Questions
What is ones complement in binary?
Ones complement is a method of representing signed integers in binary by flipping (inverting) all the bits of a number. Every 0 becomes 1 and every 1 becomes 0. For example, the ones complement of 00101010 (42 in 8-bit binary) is 11010101 (213 as unsigned, or -42 in ones complement signed representation). This system uses the most significant bit (MSB) as a sign bit: 0 for positive numbers and 1 for negative numbers. Ones complement was used in early computers like the UNIVAC and CDC 6600, though it has been largely replaced by twos complement in modern systems due to its simpler arithmetic properties.
How does ones complement differ from twos complement?
The key differences are in how negative numbers are represented and how arithmetic works. Ones complement negates by flipping all bits, while twos complement flips all bits and then adds 1. Ones complement has two representations of zero: positive zero (00000000) and negative zero (11111111), whereas twos complement has only one zero. In ones complement arithmetic, end-around carry must be added back when overflow occurs, complicating addition circuits. Twos complement avoids this issue and provides one extra negative number in its range. For 8 bits, ones complement ranges from -127 to +127, while twos complement ranges from -128 to +127.
Why was ones complement used in early computers?
Ones complement was popular in early computing because negation is trivially simple: just invert every bit, which can be done with a single layer of NOT gates and requires no sequential logic. This made the hardware for negation very fast and cheap. Computers like the UNIVAC 1100 series and CDC 6600 used ones complement arithmetic. The trade-off was more complex addition logic (due to end-around carry) and the dual representation of zero. As transistor costs decreased and circuit design improved, the advantages of twos complement (simpler addition, single zero) outweighed the simplicity of ones complement negation, and virtually all modern processors use twos complement.
What is end-around carry in ones complement addition?
End-around carry is a technique required when adding ones complement numbers. If the addition of two n-bit numbers produces a carry out of the most significant bit position, that carry must be added back to the least significant bit of the result. For example, adding 01010 (10) and 11001 (-6 in ones complement) gives 1 00011 with a carry. Adding the carry back gives 00100 (4), which is correct since 10 + (-6) = 4. Without end-around carry, the result would be off by one. This extra step adds complexity to the arithmetic logic unit and is the primary reason modern computers prefer twos complement, which handles addition without this correction.
References
Reviewed by Manoj Kumar, Mathematics Educator ยท Editorial policy