Search code examples
javascriptnode.jsbit-manipulationxor

Bitwise operators in node.js with big numbers


Trying to get a xor of two big numbers, the result is not correct.

example:

 >  7894237947293^4353453453
105105424

while on python, for example, it gets the correct answer:

>>> 7894237947293^4353453453
7898549962768

How can I made a xor on node.js?


Solution

  • Use bignum lib https://github.com/justmoon/node-bignum

    var bignum = require('bignum');
    
    var b = bignum('7894237947293').xor('4353453453');