JavaScript integers can go up to 2^53, yet all bit operations only go up to 2^32. Sometimes I need to perform bit operations on numbers between 2^32 and 2^53, so I have to write substitute functions for all the bit operations:
Here's what I have so far:
function lshift(num, bits) {
return num * Math.pow(2, bits);
}
function rshift(num, bits) {
return Math.floor(num / Math.pow(2, bits));
}
Is this the best way to implement the shift functions?
I now need to implement & and |. In my code I often have to & by 127 and 128 but I'm not sure of how to do so.
I don't need ~ or ^, but they could be included in the answer for completeness I guess.