3

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?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This is not right. F is hexa while your answer says NaN. It actually does base 10 to base 2 untill you do the base to parseint like console.log(parseInt(number, 16).toString(2));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.