Skip to content

Instantly share code, notes, and snippets.

@andyfoster
Forked from tleunen/bit-reverse.js
Last active September 7, 2015 00:16
Show Gist options
  • Save andyfoster/0ce10e758b1a56fdae8c to your computer and use it in GitHub Desktop.
Save andyfoster/0ce10e758b1a56fdae8c to your computer and use it in GitHub Desktop.
Function to reverse the bits of a given integer
function bitRev(N) {
var r = 0;
val = 0;
while(N > 0) {
val = N&1;
N >>= 1;
r += val&1;
r <<= 1;
}
r >>= 1;
return r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment