-
-
Save andyfoster/0ce10e758b1a56fdae8c to your computer and use it in GitHub Desktop.
Function to reverse the bits of a given integer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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