Last active
September 17, 2018 13:23
-
-
Save moorthy-g/bb3716303384365bce7b98b67af14fd1 to your computer and use it in GitHub Desktop.
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
//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