Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hexadecimal to binary in Nodejs

I have this hexadecimal in a nodejs Tcp Client

82380000000000000400000000000000

I have used parseint function to convert it to

1.73090408076117e+38

But i need to get its binary representation that is

10000010001110000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000

Ho can i get this binary representation from the above hexadecimal format?

like image 360
Danstan Avatar asked Apr 11 '26 22:04

Danstan


1 Answers

Using the toString specifying the base as the parameter should make it. For example, if you want to convert it to a binary string, after parsing it to an integer:

var number = '82380000000000000400000000000000';
console.log(parseInt(number).toString(2));

In case you want an hexadecimal string, just use .toString(16);

If you don't want to parse the string with the number:

var number = 82380000000000000400000000000000;
console.log(number.toString(2));

Hope this helps.

like image 94
Pablo Abad Avatar answered Apr 13 '26 13:04

Pablo Abad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!