Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 347
griffon vulture Avatar asked Dec 19 '22 14:12

griffon vulture


1 Answers

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

var bignum = require('bignum');

var b = bignum('7894237947293').xor('4353453453');
like image 104
Nikolay Lukyanchuk Avatar answered Dec 22 '22 03:12

Nikolay Lukyanchuk