What is the One's Complement?
The one's complement of a binary number is formed by inverting (flipping) every bit: each 0 becomes a 1 and each 1 becomes a 0. Because the result depends on how many bits you use, you must choose a bit width such as 4, 8, 16, or 32 bits. This representation was used in early computers to encode signed integers and is still important when studying binary arithmetic and error-detection checksums.
How to Use This Calculator
Enter a non-negative decimal number, pick a bit width, and the calculator masks the number to that width, flips all the bits, and shows you both the binary and decimal forms of the result. If your number is larger than the width allows, only the lowest bits within the width are kept before flipping.
The Formula Explained
We compute $$\text{ones} = (\sim n) \,\&\, (2^{w} - 1)$$ The term \(2^{w} - 1\) is a mask of w ones (for 8 bits that is \(11111111 = 255\)). Bitwise NOT (\(\sim\)) flips every bit of n, and the mask discards any bits above the chosen width so the answer stays within range.
Worked Example
Take the number 5 in 8-bit. In binary, \(5 = 00000101\). Flipping every bit gives \(11111010\), which equals 250 in decimal. So the one's complement of 5 in 8 bits is 250. In 4-bit, \(5 = 0101\), flipped is \(1010 = 10\).
FAQ
How is one's complement different from two's complement? Two's complement adds 1 to the one's complement, which avoids having two representations of zero.
What is the one's complement of 0? In 8-bit it is \(11111111 = 255\) — all bits become 1.
Why does the answer change with bit width? Flipping bits depends on how many bits exist; wider widths add more leading 1s, producing a larger decimal value.