Reputation: 53
I'm working on my HW for computer architecture and I came across the following problem:
A = 247
B = 2371) 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?
Upvotes: 5
Views: 2728
Reputation: 52538
If the problem was "assume that A and B are stored in an 8 bit signed integer", then it would make sense. Storing A = 247 in a signed 8 bit integer yields a value of -9, storing B = 237 yields a value of -19. Otherwise, it doesn't make sense. A signed 8 bit integer cannot have a value of 247 or 237.
Upvotes: 0
Reputation: 19353
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"
Upvotes: 3
Reputation: 231103
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.
Upvotes: 8
Reputation: 8032
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.
Upvotes: 1