Skip to content

Instantly share code, notes, and snippets.

@leeight
Created June 20, 2014 13:54
Show Gist options
  • Save leeight/b83707023bcc3c354f9f to your computer and use it in GitHub Desktop.
Save leeight/b83707023bcc3c354f9f to your computer and use it in GitHub Desktop.
JavaScript Double 2 IEEE754 format
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( '' );
}
@leeight
Copy link
Author

leeight commented Jun 20, 2014

toIEEE754(3.1415926) === '0100000000001001001000011111101101001101000100101101100001001010'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment