Reputation: 15
I have to say what the output of the program for w = 33. I do not know how to do it. Does anyone have an idea how to solve this without writing the binary representation of each number?
void notChicken(int w)
{
unsigned int v1 = 0x12345678;
unsigned int v2 = 0x87654785;
unsigned int v3 = 0xffffffff;
unsigned int tmp;
tmp = (v1 >> 3) | (v2 << 3);
tmp &= v3 & ~(v3 << (w >> 1));
printf("%8x\n", tmp);
}
Thanks
Upvotes: 0
Views: 73
Reputation: 9213
Although not a good idea, lets try to break down your operation.
You have given w = 33
The last part -
v3 & ~(v3 << (w >> 1))
is going to evaluate as v3 & ~(v3 << 16)
v3 << 16
is 0xffff0000
and ~
of that is 0xffff
since v3
is all ones you get 0xffff
. This will mask off the upper 16 bits of the previous computation.
Now (v1 >> 3) | (v2 << 3);
We care only about the lower 16 bits.
>> 3
is dividing by 8 and << 3
is multiplying by 8.
So the result of first part will be
0x2468ACF | 0x3B2A3C28
Keeping only the lower 16 bits
0x8ACF | 0x3C28
Finally I don't know how you are going to do the OR without writing the bitwise representation. I can help with the last hex. It will be F
.
Upvotes: 2