Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created July 17, 2016 00:24
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 jianminchen/5a866f2abe5f6afcf6a17ef9bbd4c05d to your computer and use it in GitHub Desktop.
Save jianminchen/5a866f2abe5f6afcf6a17ef9bbd4c05d to your computer and use it in GitHub Desktop.
reverse bit 32 unsigned integer - study code
public class Solution {
public long reverse(long A) {
long rev = 0;
for (int i = 0; i < 32; i++) {
rev <<= 1;
if ((A & (1 << i)) != 0)
rev |= 1;
}
return rev;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment