Created
February 27, 2017 23:08
-
-
Save Hugoberry/74436d318aed0dc2d9e1511c61f903f3 to your computer and use it in GitHub Desktop.
Function for reversing the bits in a 32bit number
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
reverse32 = (x) => | |
let | |
b0 = Number.BitwiseAnd(x,0xff), | |
b1 = Number.BitwiseShiftRight(Number.BitwiseAnd(x,0xff00),8), | |
b2 = Number.BitwiseShiftRight(Number.BitwiseAnd(x,0xff0000),16), | |
b3 = Number.BitwiseShiftRight(Number.BitwiseAnd(x,0xff000000),24) | |
in | |
Number.BitwiseOr( | |
Number.BitwiseOr( | |
Number.BitwiseShiftLeft(reverse(b0),24), | |
Number.BitwiseShiftLeft(reverse(b1),16)), | |
Number.BitwiseOr( | |
Number.BitwiseShiftLeft(reverse(b2),8), | |
reverse(b3))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment