Jamie Balfour

Welcome to my personal website.

Find out more about me, my personal projects, reviews, courses and much more here.

Another way of doing Two's Complement

Another way of doing Two's Complement

Two's Complement is one of those tricky little things that you can easily mess up, but what if there was an easier way of doing it than the traditional methods?

Well indeed there is.

Let's do it.

Example 1

For this example, we're going try and calculate -64. This should be easy.

The first step is to figure out how many bits we are going to need. For this we will need 8 bits. As a result our first place holder will be 128.

128 64 32 16 8 4 2 1

But wait a moment, the next thing we do, and we do this before putting down the placeholders, is we want to calculate a negative for the first place holder.

So what do we do? Well here's my way of doing it, and I don't know of anyone else who does it this way but:

0 - (128 - 64) = -64

Now write that as the first place holder instead. We always have a 1 for a negative number (the sign bit) so put a 1 underneath it.

-64 64 32 16 8 4 2 1
1

The next step is to keep adding until you get to 0.

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

Easy peasy.

-64 + 64 = 0

Example 2

Now for -34

0 - (128 - 34)

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

-94 + 64 + 16 + 8 + 4 + 2 = 0

Like I say, I don't know anyone else who uses this, though I do know of a technique similar to it. If you're teaching this to students or pupils, I don't recommend using this to teach, just to check that they got the correct answer.

Posted by jamiebalfour04 in Tech talk
twos
complement
school
binary
calculator
Comments
Powered by DASH 2.0