Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

parseInt output wrong

enter image description here
console.log(parseInt("110000111010000011100101010001010101000100000000000000000001111", 2));
The output result was wrong, even it is in google browser console.
The correct output is 7048259459772055567

I think the number is too big so nodejs cannot solve it?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Indeed, that number is much larger than Number.MAX_SAFE_INTEGER, so it cannot be accurately represented. You can use BigInts to work with numbers of this scale.

let str = "110000111010000011100101010001010101000100000000000000000001111";
let n = BigInt('0b' + str);
console.log('' + n);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading