I'm working through the exercises in the K&R book. Currently I'm stuck at exercise 2-8, which is says the following:
Write a function rightrot(x, n) that returns the value of the integer x rotated to the right by n bit positions.
The trouble I have is that I cannot seem to picture what the result SHOULD look like.
How or what do I rotate? Do I take the leftmost bit and put it to the rightmost position of x
, after x
is shifted to the left and repeat this for n
bits? Or do I take a chunk (n
bits) and put it n
bits to the right while leaving the rest of the rightmost bits unchanged?
Any helpful answer is appreciated. Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…