I need help with this question Does each of the code pieces serve for its stated
ID: 3543754 • Letter: I
Question
I need help with this question
Does each of the code pieces serve for its stated purpose? You must explain to get the full credit. Assume the following variable declaration: unsigned int a, b, c, d, mask; unsigned int *p = &a; Hint: Check the operator precedence chart, slide 49 of week 5. [3] Check if a is equal to b, or b is equal to c and c is equal to d. if (a == b || b == c && c == d) ... / / code [3] Check if the upper half of a is equal to the upper half of b. mask = 0xFF00; if (a&mask; == b&mask;) ... // code [3] Copy a's value to b, meanwhile increment pointer p. b = *p++; [3] Add the lower half of a and the lower half of b, store the result to c. The result should appear in the lower half of c, and the upper half of c should be cleared to zero. (Revised.) c = (aExplanation / Answer
a) && has higher precedence than ||
so first (b==c && c==d) will be checked
then the coming output will be checked with || (a==b)
b)
mask= 1111111100000000
the a&mask will set the first 8 bit to same as the first
8 bit of a and last 8 bit will be 0.
similarly for b
so ( a&mask== b&mask) will check the fist 8 bit of a and b is equal
or not.
c)
p has address of a, so *p give the value of a.
b=*p++ will assign the b as a,, and because here we are using
post increment the ..pointer will be increased.
d)
a<<8 means shift last 8 bit to first 8 bit position.
similerly b<<8,, and the last 8 bit will set to 0.
(a<<8 + b<<8) will add the first 8 bits of both.
then >>8 will shift it to the last 8 bit position
e)
this is easy...because b<<8 shift the last 8 bit to position
of first 8 bit ...and the last 8 bit will set to 0.
similerly b>>8 will be vice versa.
and | give the swap