BINARY

TOPIC 02 – NEGATIVE NUMBERS

 

LESSON WORK SOLUTIONS

 

 

TASK 1A – SIGNED MAGNITUDE

A) Convert 1000 1010 (signed magnitude) to base 10.

 

We know the number is negative because the first bit is 1.  So we need to convert the rest.

 

0

0

0

1

0

1

0

64

32

16

8

4

2

1

 

8 + 2 = 10

 

So, we know that 00010102 = 1010

 

And now we consider the negative, so the answer is -10.

 

B) Convert 0010 1000 (signed magnitude) to base 10.

 

So this number is positive since the left most bit is 0.  We simply convert the rest.

 

0

1

0

1

0

0

0

64

32

16

8

4

2

1

 

So the final answer is 32 + 8 = 40.

 

C) Convert 1100 0001 (signed magnitude) to base 10.

 

So the left most bit tells us it's a negative number.  We convert the rest.

 

1

0

0

0

0

0

1

64

32

16

8

4

2

1

 

That gives us 64 + 1 = 65.  So the final answer is -65.

 



 

 

 

 

TASK 1B

A) Convert 17 to Signed Magnitude binary.

 

So we know that the left most bit is a 0 since our number is positive.  Also, we will assume that we are still working with a byte for binary.

 

0

0

1

0

0

0

1

64

32

16

8

4

2

1

 

 

So, adding the left most zero, our final answer is 0001 0001.

 

B) Convert -17 to Signed Magnitude binary.

 

Since we are dealing with the negative value from A, we simply have to change the leftmost bit to 1.

 

So our final answer is 1001 0001.

 

C) Convert -100 to Signed Magnitude binary.

So the leftmost bit will be a 1.  We convert the rest.

 

1

1

0

0

1

0

0

64

32

16

8

4

2

1

 

Our final answer, after adding the left 1, is 1110 0100.


TASK 1C

A) Convert 0010 0001 from unsigned binary to signed binary.


So, we need to reserve the leftmost bit for sign.  We can do this by replacing the leftmost zero to one.

 

Solution: 1010 0001

 

Of course, one can argue that it would be best to add one (or more) bit(s) to the left in order to include a sign bit.  But we won't worry about that here (at least not until C).

 

B) Convert 0110 0110 from unsigned binary to signed binary.


Again, because the leftmost bit is not used for magnitude, we can just make it 1 for sign.

 

Solution: 1110 0110

 

C) Convert 1011 0111 from unsigned binary to signed binary.

 

This time, the leftmost bit is used to specify magnitude.  So we cannot use it for sign.  So we have to add a bit.

 

Solution: 1 1110 0110

 

Or perhaps if we want to keep using bytes and multiples of bytes, our solution could look like this instead:

 

Solution 2: 1000 0000 1110 0110

 

Both solutions above are fine.

TASK 2A

A) Give the One's Complement of 0101 1010.

We simply invert each bit.

 

Solution: 1010 0101

 

B) Give the One's Complement of 0110 1100.


Again, we simply invert each bit.

Solution: 1001 0011

C) Give the One's Complement of 1001 1001.


I accidentally gave you a bit of a trick question here.  If our starting number is an unsigned number that we need to put into one's complement form, then we need to add at least one bit on the left before taking the one's complement.

 

Solution #1:


So, 0 1001 1001 in one's complement is 1 0110 0110.

 

Solution #2:

 

Perhaps we want to keep in our size as multiples of bytes.

 

So, 0000 0000 1001 1001 would become 1111 1111 0110 0110.

 

Note: You will not get a question like this on the quiz.


TASK 2B

A) Convert 17 from base 10 to one's complement binary.

We start by getting its binary form.


0

0

1

0

0

0

1

64

32

16

8

4

2

1

So, 17 is 1 0001.  We want it to be one byte in size, so its 0001 0001 (by simply adding zeros on the left).

 

We don't invert the bits since the number is positive. 

 

Solution: 0001 0001

 

B) Convert -17 from base 10 to one's complement binary.

 

From A), we know that 17 is 0001 0001.  We now simply invert all the bits.

 

Solution: 1110 1110

 

C) Convert 17 from base 10 to one's complement binary.


We first convert 113 to binary.

 

1

1

1

0

0

0

1

64

32

16

8

4

2

1

 

So 11310 is equal to 111 00012.  We want to work with a byte, so we tack on a zero on the left.  So, we are at 0111 0001.

 

Now, we simply invert all bits.

 

Solution: 1000 1110


TASK 2C

A) Convert 0110 from one's complement binary to base 10.

The leading number is 0.  So the value is positive and there is no need to invert bits.

 

1

1

0

4

2

1

 

So, the answer is simply 4 + 2.

 

Solution: 6


B) Convert 1010 from one's complement binary to base 10.


The leading bit is 1, so the value is negative.  Therefore, we start by inverting the bits.

 

Result of inversion: 0101

 

Now we convert to decimal. 
 

1

0

1

4

2

1

                                          
So, we have 4 + 1 which is 5.  Of course, it is a negative value.

 

Solution: -5

C) Convert 0101 from one's complement binary to base 10.


So from the previous question, we know that 101 is 5.  The value is positive so we don't need to invert anything.

 

Solution: 5

 

TASK 3A

A) Convert 43 to two's complement binary form.


It's positive.  So we simply convert to binary.


0

1

0

1

0

1

1

64

32

16

8

4

2

1


So, 43 is 010 1011.  We want it to be a byte though so 0010 1011.

 

Solution: 0010 1011


B) Convert -43 to two's complement binary form.


It's negative.  So we follow the process of converting the positive value to binary, then take the one's complement, then add 1.

 

So 43 in binary is  0010 1011 (from part A)

 

Now we take the one's complement to get 1101 0100.


And finally, we simply add 1.

 

Solution: 1101 0101


C) Convert -104 to two's complement binary form.


It's negative but we start with converting 104 to binary.

 

1

1

0

1

0

0

0

64

32

16

8

4

2

1

 

So, 104 in binary is 0110 1000. 

 

Now we take the one's complement: 1001 0111.

 

And we add 1.

 

Solution: 1001 1000


TASK 3B

A) Convert 1001 1001 from two's complement binary to decimal.

It's negative.  So we have to undo the processed done to put it in two's complement form.

 

We start off by removing 1 to get 1001 1000.

 

Then we invert all the bits to get 0110 0111.

 

Now we convert that to decimal:

 

 

1

1

0

0

1

1

1

64

32

16

8

4

2

1


So the value is 64+32+4+2+1 = 103.

 

Of course, that is negative.

 

Solution: -103

B) Convert 1100 0110 from two's complement binary to decimal.

Again, it's negative, so we have to undo the processes that put it in two's complement.

 

We start off by removing 1 to get 1100 0101.

 

Now we invert bits to get: 0011 1010.

 

Now we convert to base 10.

 

 

0

1

1

1

0

1

0

64

32

16

8

4

2

1


So, the value is 32+16+8+2 = 58.

 

Of course, it's a negative value.

 

Solution: -58


C) Convert 0101 1011 from two's complement binary to decimal.

We saved the easiest one for last.  This number is positive.  So we simply need to convert it to base 10 and we are done.

 

1

0

1

1

0

1

1

64

32

16

8

4

2

1


So, our value is 64+16+8+2+1 = 91

 

Solution: 91

 

TASK 4A


A) Convert -128 to Offset binary form with starting point -128.

So, -128 is equal to 0000 0000 as that is the start point.

B) Convert 10 to offset binary form with starting point -128.


One solution would be to count there:


NUMBER     OFFSET BINARY

-128            0000 0000               

-127            0000 0001
-126            0000 0010

.

.

.

And so on…

 

But that would get pretty long. 

 

So let's consider the counting table with an extra column that simply states the usual value for that binary number.

 

NUMBER     OFFSET BINARY     USUAL VALUE

-128            0000 0000                0

-127            0000 0001                1
-126            0000 0010                2

.

.

.

10               ???? ????                138

 

So, from the table above, we can tell that usual value is 128 higher than the number.  (That's the offset value.)

 

So, the offset binary for 10 with be the usual value for 138.  So we can simply convert 138 to binary and that will be our answer.


Using the chart, we can figure out that 138 is equal to 128 + 8 + 2 which gives us:

 

1

0

0

0

1

0

1

0

128

64

32

16

8

4

2

1

 

So, 138 is usually 1000 1010.  However, that is the binary offset for our value 10.

 

Solution: 1000 1010.


C) Convert 53 to offset binary form with starting point -128.

 

So we have the same offset as in B which means that we add 128 to 53 giving us 181.

Now we simply convert 181 to binary like normally to get our answer.

 

Using the chart, we can figure out that 181 is 128 + 32 + 16 + 4 + 1.

 

1

0

1

1

0

1

0

1

128

64

32

16

8

4

2

1

 

Solution: 1011 0101


TASK 4B

A) Convert 0000 0010 from offset binary form (starting point -128) to decimal.


We will count this one out.

 

-128            0000 0000
-127            0000 0001
-126            0000 0010

Got it!  So the answer is -126.

 

Solution: -126

B) Convert 0100 1001 from offset binary form (starting point -128) to decimal.


So counting will not be effective here.  But remember that the binary value is off by 128.  So if we convert the binary number to decimal, we can then subtract 128 to get the actual value.

So let's convert 0100 1001 to decimal like normally.

 

0

1

0

0

1

0

0

1

128

64

32

16

8

4

2

1

 

So the value is 64+8+1 = 73. 

 

Now the value 73 is actually 128 higher that the answer.  So, 73 – 128 gives us -55.

Solution: -55

 

C) Convert 1100 1011 from offset binary form (starting point -128) to decimal.

Again, we start by converting to decimal.

 

1

1

0

0

1

0

1

1

128

64

32

16

8

4

2

1


The value we get is 128+64+8+2+1 = 203.

 

Now we remove the offset so we do 203 – 128 to get 75.

 

Solution: 75


TASK 5A

A) Convert 0110 0111 from base -2 to base 10.


So we start with the chart.  Remember that every second number is negative.  If you can't remember why, simply write the values as powers of -2.  The powers with odd exponents end up negative while the ones with even exponents end up positive.

0

1

1

0

0

1

1

1

-128

64

-32

16

-8

4

-2

1

 

So, we get the value 64 + -32 + 4 + -2 + 1 giving us 37.

 

Solution: 37

B) Convert 1011 0100 from base -2 to base 10.


Right to the chart.

 

1

0

1

1

0

1

0

0

-128

64

-32

16

-8

4

-2

1

 

So, we get the value -128 + -32 + 16 + 4 giving us -140.

Solution: -140


C) Convert 0101 0101 from base -2 to base 10.

The chart:

 

0

1

0

1

0

1

0

1

-128

64

-32

16

-8

4

-2

1


The total is 64 + 16 + 4 + 1 equals to 85.

 

Solution: 85

 

TASK 5B

A) Convert 45 from base 10 to base -2.

 

 Let's consider an empty chart.

 

 

 

 

 

 

 

 

 

-128

64

-32

16

-8

4

-2

1

 

This is pretty tough. I know that if we consider only positive numbers under 45, we won't get enough.  So we need to start with 64.

 

0

1

 

 

 

 

 

 

-128

64

-32

16

-8

4

-2

1

 

Now we are at 64.  We have to remove 19 to get to 45.  To do that, the only way is to include a -32.  Otherwise, the best I would be able to remove is -10 (from -8 and -2).

 

So we put a 1 over -32.

 

0

1

1

 

 

 

 

 

-128

64

-32

16

-8

4

-2

1

 

Now we are at 32.  We need to go up by 13 to get to 45.  We must include 16 because if we didn't we couldn't get anything to add up to 13.

 

0

1

1

1

 

 

 

 

-128

64

-32

16

-8

4

-2

1

 

So now we have 48.  We need to go down by 3.  To do that, we need to remove 8.

 

So we put a 1 over the -8.

 

0

1

1

1

1

 

 

 

-128

64

-32

16

-8

4

-2

1

 

We are now at 40.  We need to add 5.  We can do that by placing a 1 over the 4 and the 1. 

 

0

1

1

1

1

1

0

1

-128

64

-32

16

-8

4

-2

1

 

So the final answer is 0111 1101.

 

Solution: 0111 1101

 

B) Convert -101 from base 10 to base -2.

 

Let's start with the chart.

 

 

 

 

 

 

 

 

 

-128

64

-32

16

-8

4

-2

1

 

I'm thinking I will start with -128. 

 

1

 

 

 

 

 

 

 

-128

64

-32

16

-8

4

-2

1

 

So we are at -128.  We need to go up by 27.  So we have to include 64 (cause the other positive numbers don't add up to 27.)

 

1

1

 

 

 

 

 

 

-128

64

-32

16

-8

4

-2

1

 

So we are at -64.  We need to add -37.  To do that, we need to include -32.

 

1

1

1

 

 

 

 

 

-128

64

-32

16

-8

4

-2

1

 

We are now at -96.  We need to add -5. 

 

This gets tough here.  If we include 16, we'd be over by 11 and there would be no way of adding up to -11.  So 0 over 16.

 

1

1

1

0

 

 

 

 

-128

64

-32

16

-8

4

-2

1

 

We are still at -96 and need to add -5.  This can get tricky.  But after a bit of playing around, we can see that adding up the remaining four values (-8 + 4 + -2 + 1) gives us -5. 

 

1

1

1

0

1

1

1

1

-128

64

-32

16

-8

4

-2

1

 

Solution: 1110 1111

 

C) Convert -59 from base 10 to base -2.

 

These feel a little like puzzles.  Let's start with the chart.

 

 

 

 

 

 

 

 

 

-128

64

-32

16

-8

4

-2

1

 

So if we add up -32 and -8 and -2, we only get -40.  That's not enough.  So we need to start with -128.

 

1

 

 

 

 

 

 

 

-128

64

-32

16

-8

4

-2

1

 

We are at -128 now.  We need to go up by 69.  So that's pretty easy as that is 64 + 4 + 1.  Hurray!

 

1

1

0

0

0

1

0

1

-128

64

-32

16

-8

4

-2

1

 

Solution: 1100 0101


TASK 6

QUESTION: Of the five discussed methods to represent negative numbers in binary, which one is used in all (or almost all) computer systems today?

Answer: Two's Complement