Negative Binary Strings

Ways to represent binary strings as negative values.

Part of AS Computer Science, in case you're wondering.

One's Complement

This is the simple inversion of a binary string. If you have a string of binary digits, like 01101110 or whatever, simply invert all digits. If it's a 1, make it a 0. If it's a 0, make it a 1. Applying this to the binary string above, we would get 10010001.

Note that this is not a way to write a negative binary value. It's just something needed for one of the methods we'll see below.

Two's Complement

There are two methods for this.

Method 1

This method uses one's complement as a stepping stone. If we have a binary string, like 10110001, we first apply one's complement: 01001110. Now, we add a singular 1 to this (binary addition). In the case above, adding a 1 yields 01001111.

Remember, for binary addition with two digits:

In the case of 1+1=10, the 1 is carried to the next digit and is added there. This brings us to three digit binary addition. The rules above still hold true, the only difference is that 1+1+1=11, where the 1 is carried.

Method 2

This is faster. Up to, and including, the first 1 in our binary string, we leave it as-is. Everything after that is inverted.

If we have 11001010, we would end up with 00110110.

Remember that we read binary digits from right to left, like Arabic.

This doesn't make sense?

The deal is with converting back to denary, the numbers need to be converted with the appropriate column headings. For base 2, this is 2 to the x power. The left-most heading needs to be negative.

If, for example, we have 01101000, we get a denary value of 104. If we performed the steps detailed above, and convert back to denary, we don't get the negative version of that value. Exhibit A: 10011000 does not yeild -104.

For proper conversion, we need to change the left-most heading to be a negative value.

-128 64 32 16 8 4 2 1
1 0 0 1 1 0 0 0

-128 + 16 + 8 = -104

This article was written on 06/09/2023 and modified the following day. If you have any thoughts, feel free to send me an email with them. Have a nice day!