not exactly understanding the function described here:
Write following function:
Its value should be the result of shifting the bits in i to the left by n places, with the bits that were "shifted off" moved to the right end of i.Code:unsigned int rotate_left(unsigned int i, int n); /* prototype *
Ex. the call rotate_left(0x1234,4) should return 0x2341, if integers are 16bits long.
What I am not understanding is how do I access the "bits" and shift these values around??
for example, a 16bit code could be 0453A678B123C456 and shifting 5 to left would return 0678B123C456453A Right???
the leading zero is always 0, as that is what I understood to be the bit designating the sign of the whole "string" of numbers
0 = positive
1 = negative
If this return I have listed is correct, then do you access the bits by a simple expression?? All we played around with in understanding the logic is an expression like
i = i << 2; or i =<< 2;
j = j >> 5; or j =>> 5;
does the following code work in bit shifting??
unsigned int rotate_left(unsigned int i, int n)
This doesn't look right compared to similar examples in book. I am stumped with the bitwise operators needed to access bits..to set, clear and test a bit.
Anyone got any good examples to help me??