Skip to content

Instantly share code, notes, and snippets.

@Hugoberry
Created February 27, 2017 23:08
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 Hugoberry/74436d318aed0dc2d9e1511c61f903f3 to your computer and use it in GitHub Desktop.
Save Hugoberry/74436d318aed0dc2d9e1511c61f903f3 to your computer and use it in GitHub Desktop.
Function for reversing the bits in a 32bit number
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