mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2026-01-16 00:42:46 +01:00
Fix bug in making operations upon really big numbers
This commit is contained in:
@@ -3,7 +3,7 @@ app.set('expression', function() {
|
||||
|
||||
var exprRegex = /^(-?(?:\d+|0x[\d,a-f]+))\s*(<<|>>|>>>|\||\&|\^)\s*(-?(?:\d+|0x[\d,a-f]+))$/;
|
||||
var listRegex = /^(-?(?:\d+|0x[\d,a-f]+)\s?)+$/;
|
||||
var notRex = /^(~)(-?(?:\d+|0x[\d,a-f]+))$/
|
||||
var notRex = /^(~)(-?(?:\d+|0x[\d,a-f]+))$/;
|
||||
|
||||
return {
|
||||
canParse: function(string) {
|
||||
@@ -92,12 +92,9 @@ app.set('expression', function() {
|
||||
this.value = parseInt(input);
|
||||
this.hex = toHex(this.value.toString(16));
|
||||
this.dec = this.value.toString(10);
|
||||
this.bin = (this.value>>>0).toString(2);
|
||||
// >>> 0 makes negative numbers like -1 to be displayed as '11111111111111111111111111111111' in binary instead of -1
|
||||
this.bin = this.value < 0 ? (this.value >>> 0).toString(2) : this.value.toString(2);
|
||||
this.kind = this.input.indexOf('0x') > -1 ? 'hex' : 'dec';
|
||||
this.other = this.kind == 'dec' ? this.hex : this.dec;
|
||||
}
|
||||
|
||||
Operand.prototype.valueOf = function () {
|
||||
return this.value;
|
||||
};
|
||||
});
|
||||
@@ -106,7 +106,13 @@ describe('launch of application', function() {
|
||||
{ label: '3', bin:'00000011', other: '0x3'}])
|
||||
});
|
||||
|
||||
it('should do XOR or large numbers', function() {
|
||||
|
||||
return assertOperation('0x0001000000003003^0x3001800400000fc1',
|
||||
[{ label: '0x0001000000003003', bin:'0000000000000001000000000000000000000000000000000011000000000011', other: '281474976722947'},
|
||||
{ label: '0x3001800400000fc1', bin:'0011000000000001100000000000010000000000000000000001000000000000', other: '3459186743465480000'},
|
||||
{ label: '0x2003', bin:'0000000000000000000000000000000000000000000000000010000000000011', other: '8195'}])
|
||||
});
|
||||
|
||||
it('should do prefer hex result', function() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user