Como @Doug Currie puso necesita para representar el número de 64 bits como dos números, y luego hacer las operaciones bit a bit sobre ellos. El código que he usado es:
//Constructor for a Long..
function Long(high, low) {
//note: doing "or 0", truncates to 32 bit signed
//big-endian 2's complement int..
this._high = high | 0;
this._low = low | 0;
}
Long.prototype.rotateLeft = function(bits) {
var newHigh;
if(bits === 32){ //just switch high and low over in this case..
newHigh = this._low;
this._low = this._high;
this._high = newHigh;
} else {
newHigh = (this._high << bits) | (this._low >>> (32-bits));
this._low = (this._low << bits) | (this._high >>> (32-bits));
this._high = newHigh;
}
return this; //for chaining..
};
//Rotates the bits of this word round to the right (max 32)..
Long.prototype.rotateRight = function(bits) {
var newHigh;
if(bits === 32){ //just switch high and low over in this case..
newHigh = this._low;
this._low = this._high;
this._high = newHigh;
} else {
newHigh = (this._low << (32-bits)) | (this._high >>> bits);
this._low = (this._high << (32-bits)) | (this._low >>> bits);
this._high = newHigh;
}
return this; //for chaining..
};
para usarlo intente ejecutar: console.log(new Long(0,1).rotateLeft(4));
continuación, la inspección de las propiedades _high y GIRATORIO BAJO.
¿Sabe usted para asegurarse de que su Javascript siempre se ejecuta en una plataforma de 64 bits? – Amber
p.s. Voto a favor de cualquiera que me diga que no haga esto en JavaScript. ¡No es útil! Y * sé * que este no es el tipo de tarea para la cual JavaScript es adecuado. Pero necesito hacerlo de todos modos. KTHXBAI. – Jeff
no es que yo te crea, pero si JavaScript lo almacena en un doble, entonces es un doble no un int de 64 bits (independientemente de la señal). –