Last active
May 7, 2017 19:17
-
-
Save aautar/8a9046f7bf912c6238333f6dadb18337 to your computer and use it in GitHub Desktop.
This file contains 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 stuffInt64BytesIntoNumber(_arrayBuffer) | |
{ | |
// get a DataView over the ArrayBuffer | |
var dv = new DataView(_arrayBuffer); | |
// read bytes from DataView into array | |
var bytes = []; | |
for(let i=0; i<8; i++) { | |
bytes.push( dv.getUint8(i) ); | |
} | |
// turn each byte into a padded, binary string | |
var binaryStringsArr = bytes.map(function(b) { | |
return b.toString(2).padStart(8, "0"); | |
}); | |
// concat into binary string | |
var binaryString = binaryStringsArr.join(''); | |
// parse as Number (accurate up to 52 bits, precision loss after that) | |
return parseInt(binaryString, 2); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment