One's Complement to Decimal, Table Conversion Question

4.9k Views Asked by At

I have been supplied with the following table to indicate one's complement:

One's complement table

This table suggests that -5 in one's complement signed binary equals 10000101. However, guidance found elsewhere suggests that -5 in 'true' one's compliment binary is as follows: 11111010

I'm very confused as to why 10000101 would equal -5, as when you convert -5 to one's complement binary, it equals 11111010. I would appreciate some guidance on how this table interacts/works with known rules about one's complement.

2

There are 2 best solutions below

0
On

Explanation

One's complement are used to add negative to positive numbers. But there is a one offset error when we compute with the one's complement.

For example if the msb-sign is used for sign bit, the only positives we have now is $0$ to $127$ where sign(msb) bit is 0, that is: 0xxxxxxx.

Likewise we have $-0$ to $-127$, where sign(msb) bit is 1: 1xxxxxxx. For these two representations we spot the one offset error, i.e. we don't need two negative zeros, only one. Read wiki for more explanation.

So we add 1 producing a so-called 2's complement computation. $0$ is $00000000_2$ and $-1$ is $11111111_2$ not $-0$. Here we see one's complement in action. Say we want to make $1$ i.e. $00000001_2$ negative: We invert it using one's complement: $11111110_2$. But this is $-2$, so instead we add $1$ and get $-1$ in two's complement. Now the correct representation is $11111111_2$.

Example

We want to compute: $-5 + 27$. We know that the answer is: $22$.

First convert $5$ to $-5$ using 1's complement:

$00000101_2 \oplus 11111111_2 = 11111010_2.$ (i.e. invert all bits)

Now add $27$ to two's complement of $-5$:

$00011011_2 + 11111010_2 + 1_2 = 00010110_2.$

Result:

$00010110_2 = 22.$

0
On

That table is definitely wrong. The bit patterns in its body are the sign-and-magnitude representation of the number in its rightmost column not the one's complement representation.