Objectives

Students will be able to:

  • Convert a positive binary or denary integer to a two's complement 8-bit integer and vice versa
  • Convert a negative binary or denary integer to a two's complement 8-bit integer and vice versa

2's Complement

Intro to negative numbers in binary

We know how to represent a positive denary number in binary.

But what about negative numbers?

How does a computer program know that a number is positive or negative?

The answer is that the number will be arranged with a sign bit. The sign bit will tell us if the number is positive or negative.

For example, here is a byte of information. The most significant bit (the one on the left) is the sign bit.

  • If the sign bit is 1, it means the number is negative
  • If the sign bit is 0, it means the number is positive

What do you notice about the most significant bit (the one on the left)?


Representing negative numbers in binary

To represent negative number in binary there are 3 steps:

  1. represent the number as a positive number, including a sign bit.
  2. Invert it
  3. Add 1 to it

for example, let's represent the denary number -13 as an 8-biit 2's complement binary integer:

Step 1 - represent as a positive number

0-1280640320161814021 1

Step 2 - invert

1 -12816413211608041201

Step 3 - Add 1

1-12816413211608041211

Now we have -13 represented in binary.

Here is a nice video explaining the concept.

Converting a negative binary number to denary.

Now we know that the most significant bit in a 2's complement number represents -128, it is easy for us to convert 2's complement numbers to denary (decimal).

Have a look at this example and take some paper and a pen and work it out. Then, click the answer button!

1-128 064 132 016 18 04 02 11

-87

   Task

Click on the Exercises tab and complete as many as you can.

Food For Thought

2's complement is a technique that allow's us to work with negative numbers in binary. All we need to do is create a sign bit. With 8 bits, the biggest number we can create is 255. But now, the most significant bit is a sign bit. What is the biggest number we can create using 7 bits of data and a sign bit?




Tags

big data cite consumer visualize quote target reputable bibliograpy predict static ubiquitous trends live


SUBSCRIBE

Join my mailing list to receive updates on the latest blog posts and other things.