Binary to decimal confusion signed numbers

In summary, the conversation discusses the confusion surrounding binary to decimal conversion and signed numbers, specifically in the context of performing arithmetic operations. The conversation explains the concept of signed integers and their limited range compared to unsigned integers. It also mentions the use of 2's-complement to convert negative numbers to their absolute value. The conversation concludes with the explanation of roll-over, where the sum of two integers exceeds the permitted range and results in an invalid computation. This can occur in computer programming and it is important to be aware of it when working with signed integers.
  • #1
mr_coffee
1,629
1
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!
 
Physics news on Phys.org
  • #2
mr_coffee said:
what the heck is going on!
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" !

Adding -15 to -18

-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! :biggrin:
 
  • #3


I can understand your confusion. Binary to decimal conversion can be tricky, especially when dealing with signed numbers. In order to convert a binary number to decimal, we use the powers of 2 method. Each digit in the binary number represents a power of 2, starting from the rightmost digit being 2^0, then 2^1, 2^2, and so on. To convert a negative binary number to decimal, we use the 2's complement method, which involves finding the 1's complement (flipping all the digits) and adding 1 to the result.

In the given example, the first step is to convert the negative number -010010 to its positive equivalent using the 2's complement method. This gives us 101110. Now, we can perform the addition using the regular powers of 2 method.

110001
+101110
= 1001111

Since we have an overflow of 1, we can ignore it and focus on the remaining digits, which gives us 001111. Converting this back to decimal gives us -15. Thus, the final answer is -15 - 18 = -33.

It is important to remember that when dealing with signed numbers, the leftmost bit (also known as the sign bit) represents the sign of the number. 0 represents a positive number, while 1 represents a negative number. In the given example, the leftmost bit of 110001 is 1, indicating a negative number.

I hope this explanation helps to clear up any confusion you may have had. Remember to always take your time and double check your conversions to avoid any errors.
 

1. What is the difference between binary and decimal numbers?

Binary numbers are base 2 numbers that use only two digits, 0 and 1, to represent values. Decimal numbers are base 10 numbers that use 10 digits, 0-9, to represent values. Binary numbers are commonly used in computer systems, while decimal numbers are used in everyday life.

2. How do you convert a binary number to a decimal number?

To convert a binary number to a decimal number, you can use the positional notation system. Each digit in a binary number represents a power of 2, starting from the rightmost digit. Simply multiply each digit by its corresponding power of 2 and add them together to get the decimal equivalent.

3. What are signed numbers?

Signed numbers are numbers that can be either positive or negative. In binary, signed numbers are represented using a sign bit, where 0 represents a positive number and 1 represents a negative number. This allows for the representation of both positive and negative values in binary form.

4. How do you convert a signed binary number to a decimal number?

To convert a signed binary number to a decimal number, you can use the same method as converting a regular binary number to a decimal number. However, you must take into account the sign bit. If the sign bit is 1, the number is negative and you must take the two's complement of the remaining bits before converting to decimal.

5. Why is there confusion when converting between binary and decimal with signed numbers?

The confusion arises when trying to interpret the sign bit in signed binary numbers. In decimal, the sign of a number is represented by a positive or negative sign. But in binary, the sign is represented by a single bit, which can be tricky to interpret. Additionally, the use of two's complement to represent negative numbers can also lead to confusion.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
4
Views
15K
  • Engineering and Comp Sci Homework Help
Replies
13
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
Replies
4
Views
819
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
2K
  • Computing and Technology
Replies
4
Views
664
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
7K
Back
Top