Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS - Convert hexadecimal to float

Tags:

node.js

hex

That may sound like a weird struggle and actually easy to do, but I cannot find a working way to convert an hexidecimal in a string format into a float.

My exemple is for instance: 406ea716

If I convert it using one of the following website, I get 3.728948.

http://www.h-schmidt.net/FloatConverter/IEEE754.html http://gregstoll.dyndns.org/~gregstoll/floattohex/

I tried every single piece of code I found on the internet, but it won't return the same result.

Does it exist a module in NodeJS to perform the same conversion? If not, what can I do?

Thank you for your help.

like image 591
mentinet Avatar asked Feb 19 '16 15:02

mentinet


1 Answers

I had the same issue. try this.

Buffer('406ea716','hex').readFloatBE(0)

3.7289481163024902

like image 98
Rolland Saf Avatar answered Sep 21 '22 04:09

Rolland Saf