Ones' complement facts for kids
The ones' complement is a special way that computers can represent binary numbers, especially negative ones. Imagine you have a number made of 0s and 1s (like 0010). To find its ones' complement, you just flip every 0 to a 1 and every 1 to a 0. So, 0010 would become 1101.
This method is important in computer science because it's one of the ways early computers handled negative numbers. It's like how we use a minus sign (-) in front of a number to show it's negative (like -5). Computers use a different system for this.
In a ones' complement system, if you take a positive number and flip all its bits, you get its negative version. For example, if 0010 means 2, then 1101 would mean -2.
Many older computers, like the UNIVAC 1101 and the CDC 6600, used ones' complement. However, most modern computers today use a different system called two's complement, which is a bit simpler for them to work with.
Bits | Unsigned value | Ones' complement value |
---|---|---|
000 | 0 | 0 |
001 | 1 | 1 |
010 | 2 | 2 |
011 | 3 | 3 |
100 | 4 | −3 |
101 | 5 | −2 |
110 | 6 | −1 |
111 | 7 | −0 |
Bits | Unsigned value |
Ones' complement value |
---|---|---|
0000 0000 | 0 | 0 |
0000 0001 | 1 | 1 |
0000 0010 | 2 | 2 |
0111 1110 | 126 | 126 |
0111 1111 | 127 | 127 |
1000 0000 | 128 | −127 |
1000 0001 | 129 | −126 |
1111 1101 | 253 | −2 |
1111 1110 | 254 | −1 |
1111 1111 | 255 | −0 |
How Numbers Are Represented
In the ones' complement system, positive numbers look just like regular binary numbers. For example, 0011 is 3.
To make a negative number, you flip all the bits of its positive version. So, if 0011 is 3, then 1100 (all bits flipped) is -3.
The very first bit (on the far left) tells you if the number is positive or negative. If it's 0, the number is positive. If it's 1, the number is negative.
Here's how numbers from -7 to +7 would look in a four-bit system: + − 0 0000 1111 — Notice that both +0 and −0 exist! 1 0001 1110 2 0010 1101 3 0011 1100 4 0100 1011 5 0101 1010 6 0110 1001 7 0111 1000
Adding and Subtracting
Adding numbers in ones' complement is pretty simple. You add them just like regular binary numbers.
However, there's a special rule: if a "carry" (an extra 1) goes past the very last bit on the left, you have to add that carry back to the rightmost bit. This is called an "end-around carry".
Let's add 22 (0001 0110) and 3 (0000 0011): 0001 0110 (22) + 0000 0011 (3) =========== 0001 1001 (25) No end-around carry here, so the answer is 25.
Subtraction works similarly, but with "borrows" instead of carries. If a borrow goes past the last bit, you subtract it from the rightmost bit. This is called an "end-around borrow".
Let's subtract 19 (0001 0011) from 6 (0000 0110): 0000 0110 (6) − 0001 0011 (19) =========== 1 1111 0011 (This is an intermediate result, and we have an end-around borrow of 1) − 0000 0001 (Subtract the end-around borrow) =========== 1111 0010 (-13) The correct answer is -13.
Negative Zero
One interesting thing about ones' complement is that it has two ways to represent zero:
- Positive zero: All bits are 0 (e.g., 0000).
- Negative zero: All bits are 1 (e.g., 1111). This happens because if you flip all the bits of positive zero (0000), you get 1111.
Even though they look different, both +0 and -0 act like zero in calculations. If you add or subtract negative zero from another number, the original number stays the same.
Let's add -0 (1111 1111) to 22 (0001 0110): 0001 0110 (22) + 1111 1111 (-0) =========== 1 0001 0101 (Intermediate result with an end-around carry of 1) + 0000 0001 (Add the end-around carry) =========== 0001 0110 (22) The result is 22, just like 22 + 0.
Negative zero can be created when you add a number to its negative counterpart. For example, adding 22 (0001 0110) and -22 (1110 1001): 0001 0110 (22) + 1110 1001 (-22) =========== 1111 1111 (-0) This shows that 22 + (-22) equals -0 in this system.
Having two zeros can sometimes make computer programs a bit more complicated, as they need to check for both +0 and -0 if they want to be sure a value is truly zero.