0

I missed a day of class due to illness, so I checked out my profs. material for that day online and I'm stuck on this. His notes don't have an explanation on how to do it. I can do conversions between the masses (decimal to octal, hex, binary etc.), but I can't do this.

Any help? An example would really help me understand quickly. I'll post his slideshow example:

1010 0000 0100 0101 as an unsigned value
= (1 * 2^15) + (1 * 2^13) + (1 * 2^6) + (1 * 2^2) + (1 * 2^0)
= (32,768) + (8192) + (64) + (4) + (1)
= 32,768 + 8261 = 41,029 base 10



1010 0000 0100 0101 as a signed value
= - [(1 * 2^13) + (1 * 2^6) + (1 * 2^2) + (1 * 2^0)] 
= -8,261 base 10

I guess I should really attend class even when I'm sick.

Saigo no Akuma
  • 147
  • 1
  • 1
  • 11

2 Answers2

1

The difference between a signed integer and an unsigned integer is that one of the bits, in this case the leftmost bit is used to indicate if the value is positive or negatve. In this case, if the leftmost bit is 1, then the value is negative, and when the leftmost bit is 0 the value is positive.

So in the example that your professor gave,

1010 0000 0100 0101 

can be interpreted as either a signed integer or an unsigned integer, depeding on the situation. When interpreted as a signed integer, the value evaluates out

(1 * 2^15) + (1 * 2^13) + (1 * 2^6) + (1 * 2^2) + (1 * 2^0) = 41092

When interpreted as an unsigned value, you get the sign from the leftmost bit and the value of the integer from the rest of the bits

- [(1 * 2^13) + (1 * 2^6) + (1 * 2^2) + (1 * 2^0)]  = - 8261

Hope this helps!

Jesse Cai
  • 41
  • 5
  • Thanks! But here's my problem, I don't know how we got 2^15, 2^13 etc. I can't seem to find anything that explains that. I do know that 0000 = 0, 0001 = 1 etc.. But how is 1010 = 2^15 or 2^13 (when signed) when 1010 = 10? Sorry if this a noobish question. – Saigo no Akuma Nov 12 '15 at 02:18
  • See my answer: look at places where the 1's are – aggaton Nov 12 '15 at 02:19
  • That arises when you convert a binary number to a decimal number. For example, converting 1011 to decimal is 2^0 + 2^1 + 2^8 or 11. – Jesse Cai Nov 12 '15 at 02:22
1

Sign is the 15th bit. So all you have to do is basically count places with ones (i.e. 2^place) and add them together.

aggaton
  • 3,066
  • 2
  • 25
  • 36
  • Okay, so: 0100 1000 0001 = (1*2^10) + (1*2^7) + (1*2^0) = 1153 base 10. Is that correct? – Saigo no Akuma Nov 12 '15 at 02:29
  • Just a quick follow up, when you do the signed int. and the leading is a 1, it equals negative, equating the 2^place to -1, and continuing on to the next, is that correct? ex. 1100 1000 0001 = -(2^10 + 2^7 + 2^0) – Saigo no Akuma Nov 12 '15 at 02:49
  • 1
    Again correct, in signed notation, the left-most bit is used to indicate sign. – aggaton Nov 12 '15 at 02:52