Question: 9. Consider the fowling C code. 12 Points int fun1(unsigned word){ return (int) ( ( word < < 24 ) >> 24); } int fun2(unsigned
9. Consider the fowling C code. 12 Points
int fun1(unsigned word){
return (int) ( ( word << 24 ) >> 24);
}
int fun2(unsigned word){
return ( (int) ( word << 24 ) >> 24);
}
Assume these are executed as a 32-bit program on a machine that uses twos-complement arithmetic. Assume also that right shift of signed values are performed arithmetically, while right shift of unsinged values are preformed logically.
Note: the difference between fun1 and fun2 is that fun1 shift the number first then cast into int, fun2 first cast then shift. Unsigned and int both has bit length equal to 32.
Fill in the following table showing the effect of these functions for several example arguments. Please use your result in hexadecimal form as the first example shows with blue color.
w fun1(w) fun2(w)
___________________________________________
0x00000076 0x00000076 0x00000076
0x00CDEFEF 0x____________ 0x_______________ (4 points)
0x1234569C 0x____________ 0x_______________ (4 points)
0x233333B8 0x____________ 0x_______________ (4 points)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
