javascript - bitwise OR unexpected result -
this line of code:
console.log((90000000000000|0).tostring());
output:
-1039687680 ( bin -111101111110000110000000000000 )
according 32-bit signed integer conversion, expect:
/--discarded--\/---------significant----------\ 10100011101101011000010000001111010000000000000 = 90000000000000 │ 11000010000001111010000000000000 or 00000000000000000000000000000000 ================================ 11000010000001111010000000000000 = -1107795968 sign/\------significant bits-------/
why obtain -1039687680 instead of -1107795968?
as mentioned in post linked, it's in two's complement format.
negative 11000010000001111010000000000000 xor 1 plus 1 equals
positive 11110111111000011000000000000000, 1039687680
finally -1039687680 gained.
Comments
Post a Comment