Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yanzhihong23/9affecdd54a4039b5a8a5ba18d560200 to your computer and use it in GitHub Desktop.
Save yanzhihong23/9affecdd54a4039b5a8a5ba18d560200 to your computer and use it in GitHub Desktop.
Representing a number as 64 bit float
function to64bitFloat(number) {
var i, result = "";
var dv = new DataView(new ArrayBuffer(8));
dv.setFloat64(0, number, false);
for (i = 0; i < 8; i++) {
var bits = dv.getUint8(i).toString(2);
if (bits.length < 8) {
bits = new Array(8 - bits.length).fill('0').join("") + bits;
}
result += bits;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment