रूप @Doug करी डाल दिया आप दो नंबर के रूप में 64-बिट संख्या का प्रतिनिधित्व करने के लिए, तो उन पर बिट के लिहाज से कार्य कर की जरूरत है। कोड मैं का उपयोग किया है है: console.log(new Long(0,1).rotateLeft(4));
तो _high और _low गुण निरीक्षण:
//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..
};
इसे चलाने की कोशिश का उपयोग करें।
स्रोत
2012-02-17 16:53:36
आप निश्चित रूप से पता है कि आपकी जावास्क्रिप्ट को हमेशा एक 64-बिट प्लेटफॉर्म पर चलने की जाएगी? – Amber
पी। किसी भी व्यक्ति के लिए डाउनवोट्स जो मुझे जावास्क्रिप्ट में ऐसा नहीं करने के लिए कहता है। अनुपयोगी! और मुझे * पता है कि यह ऐसा काम नहीं है जो जावास्क्रिप्ट के लिए उपयुक्त है। लेकिन मुझे वैसे भी ऐसा करने की ज़रूरत है। KTHXBAI। – Jeff
नहीं कि मैं आपको विश्वास करता हूं, लेकिन यदि जावास्क्रिप्ट इसे दो बार स्टोर करता है तो यह 64 बिट int (साइन के बावजूद) नहीं है। –