### Rotate by n bit positions

Write a function that rotates (

**NOT shifts**) to the right by n bit positions the bits of an unsigned char x.ie no bits are lost in this process.Your answer should print out the result in binary form

Your output should be like this:

x = 10100111 (binary) x rotated by 3 = 11110100 (binary)

x = ((2^n-1)&n)<<(length(x)-n))|(x>>n)

ReplyDelete@Softy342 your solution is not clear can you please explain it..

ReplyDeletesorry i meant that we will create a mask , here it is n so mask = 2^n - 1 (n 1s) , which will be anded with x to get the n lsbs whcih will be shifted by length of the x - n , then it will be ORRED with the x shifted by n ...just a pseudo code..not the actual c code..do psot wht you think..!

ReplyDelete@softy342 it will work fine..:)

ReplyDelete