0

My professor asked this question to us:

What is the (base 10) signed integer value of 11101101 ?

Does the answer to a question like this come down to the interpretation of the question, or is there a set in stone answer?

To me it seems to come down to interpretation, and that's why I'm asking this question to see if I am right or wrong in those regards.

Here's my thought on it:

The answer is positive 237 (if 2's complement was performed prior, and 11101101 is the signed representation)

OR

The answer is negative 19 (if assuming that 11101101 is unsigned, and we need to perform 2's complement to get 00010011)

So am I right to state that a question like this can come down to the interpretation of it? Or should the person answering this question just assume that 2's complement has already been performed? (And thus give the answer of positive 237)

Volman2014
  • 81
  • 8
  • 1
    It's not about "2's complement was performed prior" - it's how you interpret bits in computer memory. If you have bits `11101101`, and they are being read as if they are a standard signed byte, then the answer is `-19`. (I say "standard" because there are some languages which encode their 32-bit integers a bit differently - e.g. shifted left two bits, so that 0000.....00000100` represents `1`.) The conversion from `11101101` to `-19` is the interpretation - from storage to number. The answer `237` is correct if you are interpreting `11101101` as an *unsigned* byte. – Amadan Feb 04 '16 at 08:40
  • I believe I understand now! Thanks for your help. – Volman2014 Feb 04 '16 at 09:08
  • 1
    Possible duplicate of [Signed versus Unsigned Integers](http://stackoverflow.com/questions/247873/signed-versus-unsigned-integers) – David Hoelzer Feb 04 '16 at 12:24

1 Answers1

3

Consider 4 bits;

0   0000    0
1   0001    1
2   0010    2
3   0011    3
4   0100    4
5   0101    5
6   0110    6
7   0111    7

8   1000    -8
9   1001    -7
A   1010    -6
B   1011    -5
C   1100    -4
D   1101    -3
E   1110    -2
F   1111    -1

If the number is unsigned humans understand the bit pattern as the left column.

If the number is signed humans understand the bit pattern as the right column.

take decimal 10 - A 1010 -6 for example;

if signed 3 - 6 = -3 will look like this:

(3)     0011 +
(-6)    1010
----    ----
(-3)    1101

if the number is unsigned the exact same operation looks like this 3 + 10 = 13:

(3)     0011 +
(A)     1010
----    ----
(D)     1101

Notice the bit patterns stay the same, the only thing i'm changing is the human readable representation depending if the number is signed or unsigned, even the operation is the same internally (i.e addition).

James
  • 1,009
  • 10
  • 11
  • normal addition and subtraction work the same regardless of whether the bits are to be interpreted as signed or unsigned. There are other operations that don't work that way: saturating add/sub (e.g. saturate a byte to either `[-128..127]` (`f0-7f`) or `[0..255]` (`00 - ff`)), full multiplication (8b*8b->16b), absolute value. (abs is a no-op for unsigned, but not for signed). – Peter Cordes Feb 04 '16 at 18:06