A part of techInterview.org: answers to technical interview questions.
Your host: Michael Pryor
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.
For eg: -
x = 10100111 (binary)
x rotated by 3 = 11110100 (binary)
Monday, March 27, 2006
I think small modification of Shikha Sharma's solution will work:
bits = sizeof(x)*8;
x = (x <<(bits - (n%bits)) | (x >> n%bits)
assume x is unsigned.
Tuesday, March 28, 2006
This topic is archived. No further replies will be accepted.Other recent topics
Powered by FogBugz