Skip to content

Instantly share code, notes, and snippets.

@moorthy-g
Last active September 17, 2018 13:23
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 moorthy-g/bb3716303384365bce7b98b67af14fd1 to your computer and use it in GitHub Desktop.
Save moorthy-g/bb3716303384365bce7b98b67af14fd1 to your computer and use it in GitHub Desktop.
//Javascript stores integer values in upto 52 bits binary
//But, it performs bitwise operations on 32 bits only
//This gist splits 30 lowbits & the other high bits(total of 52 bits)
//helpful for bitwise operations
function bitSplitAt30(n) {
if(n > 0x3fffffff) {
const lowBits = n & 0x3fffffff;
const highBits = (n-lowBits)/0x40000000;
return [highBits, lowBits];
}
return [0, n];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment