Unsigned 64-bit bitwise AND / OR in Javascript
I looked at Stack Overflow and couldn't find an answer for this. I have bitmask values that go from 0x0000000000000001
to 0x0200000000000000,
, each representing a field in my object that can be changed. The modified fields have a corresponding mask value bitwise-OR'd together to have a single 64-bit value that can be interpreted later. But I'm having difficulty because Javascript bitwise operators convert operands to signed 32-bit values. I've tried to write unsigned 64-bit unsigned methods to simulate bitwise-OR and bitwise-AND, but ran into difficulties. My first hit was:
_bitwiseOr64: function(a, b) {
var aHi = (a >> 32);
var aLo = (a & 0xffffffff);
var bHi = (b >> 32);
var bLo = (b & 0xffffffff);
return (((aHi | bHi) << 32) + (aLo | bLo));
}
If a = 0
u b = 0x80000000
, I would like the _bitwiseOr64 result to be 0x80000000
(unsigned, because I'm dealing with bitmash here). I am not getting this kind of result. Can anyone offer help?
source to share
Take a look at this library: http://google.github.io/closure-library/api/class_goog_math_Long.html
They have several bitwise functions like add (other) and / or others that support 64-bit as well.
For Node.JS, you can use Long.js
source to share