Created
June 20, 2014 13:54
-
-
Save leeight/b83707023bcc3c354f9f to your computer and use it in GitHub Desktop.
JavaScript Double 2 IEEE754 format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function toIEEE754( d ) { | |
var a = new Float64Array( [ d ] ); | |
var b = new DataView( a.buffer ); | |
var f = []; | |
for(var i = 0; i < b.byteLength; i ++ ){ | |
var k = b.getUint8( 7 - i ); | |
var e = k.toString( 2 ); | |
var p = new Array( 9 - e.length ).join( 0 ); | |
f.unshift( p + e ); | |
} | |
return f.join( '' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
toIEEE754(3.1415926) === '0100000000001001001000011111101101001101000100101101100001001010'