Why this bitwise operation is failing in Javascript
You linked to the answer yourself:
Note that the bitwise operators and shift operators operate on 32-bit ints.
As Tim has already pointed out, bitwise operations in JavaScript use 32-bit numbers. One solution (and probably the easiest) is to use a bignum library that supports bitwise operations, such as this one: https://www.npmjs.org/package/bignum.
Another way to do it would be to break the number into words, and do the operations on the words separately, old-school style:
var a = 65527;
var b = 34359738368;
var wordSize = 4294967296; // 2^32
var ah = Math.floor(a/wordSize);
var al = a - ah*wordSize;
var bh = Math.floor(b/wordSize);
var bl = b - bh*wordSize;
var xh = ah | bh;
var xl = al | bl;
var x = xh*wordSize + xl;
All we're doing is breaking the two operands into two words (high and low), doing the operations on the words, yielding our result (x) as a high and a low word, then recombining them to make a word.
You could, of course, bundle this into a neat function:
function or64(a,b){
var w64 = 18446744073709552000; // 2^64
var w32 = 4294967296; // 2^32
if(a>w64 || b>w64)
throw new Error('operands cannot exceed 64 bits');
var ah = Math.floor(a/w32);
var al = a - ah*w32;
var bh = Math.floor(b/w32);
var bl = b - bh*w32;
return (ah|bh)*w32 + (al|bl);
}