Skip to content

Instantly share code, notes, and snippets.

@davestevens
Created January 9, 2012 09:49
Show Gist options
  • Save davestevens/1582231 to your computer and use it in GitHub Desktop.
Save davestevens/1582231 to your computer and use it in GitHub Desktop.
Best way to unsign right shift a signed integer?
int unsignedRightShift(int input, char shift) {
if(shift == 0) {
return input;
}
return (((input >> 1) & 0x7fffffff) >> (shift - 1));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment