Skip to content

Instantly share code, notes, and snippets.

@cynx
Created June 17, 2014 13:35
Show Gist options
  • Save cynx/ccc61a89f38f8ddefc46 to your computer and use it in GitHub Desktop.
Save cynx/ccc61a89f38f8ddefc46 to your computer and use it in GitHub Desktop.
C function to rotate right
unsigned rightrot(unsigned x, unsigned n)
{
while (n > 0) {
if ((x & 1) == 1)
x = (x >> 1) | ~(~0U >> 1);
else
x = (x >> 1);
n--;
}
return x;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment