Skip to content

Instantly share code, notes, and snippets.

@XcqRomance
Created December 3, 2018 07:01
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 XcqRomance/c7075ed668e31e8bf73f0c9ce91e6448 to your computer and use it in GitHub Desktop.
Save XcqRomance/c7075ed668e31e8bf73f0c9ce91e6448 to your computer and use it in GitHub Desktop.
颠倒二进制位
// 颠倒二进制位
uint32_t reverseBits(uint32_t n) {
uint32_t m=0;
for(int i=0;i<32;i++){
m<<=1;
m=m|(n&1);
//m<<=1;
n>>=1;//必须是这样的顺序,m左移32位,如果在下面,左移了33位;
}
return m;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment