Returns a string representation of the bits in a given Float 64, Expample:
> float2bin(-1234.5678);
"1100000010010011010010100100010101101101010111001111101010101101"
My first approach was
function(a){
var b=''+a<0?((a=-a)&&1):0,
c=Math,
d=~~c.floor(c.log(a)/c.log(2)),
e;
b+=(1e15+(d+1023).toString(2)).slice(-11);
a-=c.pow(2,d);
for(;b.length<64;)
e=c.pow(2,--d),
b+=e<=a?(a-=e)&0||1:0;
return b;
};
But was too long so after watch @bartaz talk on jsconf I switched to ArrayBuffer and DataView
function(a,b,c){
b=new DataView(new ArrayBuffer(8));
b.setFloat64(0,a);
for(c=8,a='';c--;)
a=(1e9+b.getUint8(c).toString(2)).slice(-8)+a;
return a
}
It was still too long so I came up with the final version with bitwise operators
function(a,b,c){
b=new DataView(new ArrayBuffer(8));
b.setFloat64(0,a);
for(a='',c=64;c--;)
a=(b.getUint8(c/8)&1<<(7-c%8)?1:0)+a;
return a
}