Skip to content

Instantly share code, notes, and snippets.

@erynofwales
Created September 8, 2011 06:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erynofwales/1202793 to your computer and use it in GitHub Desktop.
Save erynofwales/1202793 to your computer and use it in GitHub Desktop.
Do bit rotations with bit shifts in C
/* Do bit rotations. x is the data to rotate, c is the number of bits to rotate */
#define ROTATE_R(x,c) (x) = ((x) >> c) | ((x) << (sizeof(x) - c))
#define ROTATE_L(x,c) (x) = ((x) << c) | ((x) >> (sizeof(x) - c))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment