Convert between float & # 8596; int in javascript

I have a javascript program (running in jsdb that uses Mozilla Spidermonkey 1.8, not a browser) that I need to convert float and doubles to / from the corresponding number of bytes of their IEEE representations. Java Float.floatToIntBits () and Float.intBitsToFloat () and similar methods for Double.

Is there a way to compute these functions in Javascript? (and yes, I know that all javascript numbers are essentially double type)

I think I could follow the javadoc algorithms for Double.longBitsToDouble () and Float.intBitsToFloat () , but this only applies to one direction, and I need both.

+3
source share
2 answers

As I know, javascript has no such built-in methods.

Here are some things you want to have. Check out the source code: http://babbage.cs.qc.edu/IEEE-754/IEEE-754hex32.html

+1
source

All Articles