views:

235

answers:

5

I'm working on my HW for computer architecture and I came across the following problem:

A = 247
B = 237

1) Assume A and B are signed 8-bit integers stored in two's complement format. Calculate A + B using saturating arithmetic. The result should be written in decimal. Show your work.
2) Assume A and B are signed 8 bit integers stored in two's compelemnt format. Calculate A - B using saturating arithmetic.

Now, how are these even a valid questions? I know what saturating arithmetic is, but how is it valid to say that A is 247 and B is 237 when they can't be represented by an 8-bit two's complement number?

I realize the point of saturated arithmetic is in the case of a overflow/underflow to set all the bits to the extreme value but it doesn't make sense to me to ask a series of questions (there are 3 more with this same problem) involving arithmetic of numbers that can't be represented in the format they specify.

Am I wrong here?

+1  A: 

Looks wrong to me. 8-bit signed two's complement integers can be between -128 and 127. Any attempt to assign a constant 237 or 247 to an 8-bit signed two's complement variable should result in an error, depending on your language.

Aric TenEyck
It works without error in C. As well it should - there should only be an error if overflow occurs, which is not the case here. "237" is simply translated to its bit-representation, which fits in 8 bits. No difference between that and assigning the byte to 0xED
rascher
@rasher: The standard would disagree about that. Converting unsinged to signed value where it does not fit in the underlying type is implementation specified on the result. But this is an architecture question. Not a question on what C would do.
Martin York
+6  A: 

The only interpretation that makes sense is that the values given are the unsigned interpretation of the number in question; values greater than 127 are obviously out of range for an 8-bit signed twos-complement value. I agree that the question is poorly stated, however.

bdonlan
Yeah this is the only approach that makes sense to me.
Nosredna
+1  A: 

I don't know, but it might be asking: "Convert the decimal number 237 to an 8-bit integer. Now interpret those bits as an 8-bit 2's complement integer and add them".

Kinda like saying, in C:

char a = 237;
printf("%x %d\n",a, a);

Which compiles and gives you values that you would expect based on the 2's complement interpretation of the 8-bit value "237"

rascher
A: 

My guess is that the problem is designed to demonstrate to you that one of these two operations will actually work.

Of course, it's always valauble to remember that not all inputs are going to be valid...

Jere
A: 

Yes, there is a mistake in your book, complement is misspelled:

"Assume A and B are signed 8 bit integers stored in two's compelemnt format."

Rob
How is this a helpful answer?
Nathan Fellman