# Homework Help: Binary to decimal confusion signed numbers!

1. Nov 27, 2005

### mr_coffee

binary to decimal confusion!!! signed numbers!

OKay this makes no sense to me...
THe directions say:
The following binary numbers have a sign in the leftmost postion and if negative, are in 2's complement form. Perofrm the indciated airthmeic operations and verify the answers.

So i have:
110001
-010010 = ?

010010 = 18, but since we are subtracting its -18.
1 10001 is in two's compliment form so we have to convert it to its regular magnitude by taking 2's compliment of it.
which is
001110 + 1 = 001111 = 15, but since the sign is a 1 above, its -15;
so we got -15 - 18 = -33
So we know the answer has to be -33; but when u take the 2's compliment of the minuend, u end up with
010010 = 101101 + 1 = 101110;
so now we add that to the top number:
110001
+101110 = 1 011111; we have an overflow of 1, so u delete that and ur left with
011111 = 31!! what the heck is going on!

2. Nov 28, 2005

### Fermat

You rolled over!!

You are working with 6-bit binary numbers.

These numbers are, in computer jargon, signed numbers, or signed integers. In addition to this, you also have unsigned integers.

In unsigned integers, all the bits are used to give a positive number. So for a 6-bit binary number, the range of values is 0 to 2^6-1, i.e. 0 to 63.
In signed integers, the leftmost bit is used to indicate the sign. If the sign bit is set (=1), then the number is negative. Since one bit is used for the sign, then there are only 5 bits left for a numerical value. This means that for unsigned integers, the range of numeric values is: -2^5 to 2^5-1, i.e -32 to +31.

Negative numbers are in 2's-complement form. So, to get the numeric value of a negative number, you have to do the 2's-complement thingy on it.

E.g.
-15 is 11 0001
Doing the 2's-complement on it,
00 1110 +1 = 00 1111 = 15 : the absolute value.

Since the number range of a signed integer is -32 to +31, then you can't add two numbers if their sum is greater than 31 - in which case you get roll-over. And, if you add two negative numbers such that their sum is less than -32, then I guess you could call that a "roll-under" !

-15: 11 0001
-18: 10 1110
Sum:101 1111 as a 7bit number

Now as a signed 7-bit number, when we do a 2's complement on it,
010 0000 + 1 = 010 0001 = 33 : the absolute value.

Unfortunately we're not really allowed to do this as we are only supposed to be dealing with 6-bit numbers. The moral is: check your ranges. If the sum of two integers exceeds the range permitted, then they can't be added.

This is what happens in a computer when you are adding integers. If the sum exceeds the range, then you get roll-over and any computations based on that result will be invalid. Some computer languages check for this and and give you a "Operation exceeded MAXINT limit" error, or something like that. Other computer languages don't e.g. C (I'm not sure about C++, I can't remember now!)

If this is part of a question you were asked to do, then I would say that the operation (Sum) exceeds the permitted range of the (signed) integer resulting in roll-over.

Hmm, this is probably a bit more than you asked for or were expecting. I'm afraid I got a bit carried away!!