Skip to content

Instantly share code, notes, and snippets.

@supernovaplus
Created October 11, 2020 21:37
Show Gist options
  • Save supernovaplus/c0d90cca34e6998ba8d5bc7b51a6fa31 to your computer and use it in GitHub Desktop.
Save supernovaplus/c0d90cca34e6998ba8d5bc7b51a6fa31 to your computer and use it in GitHub Desktop.
function hexToDouble1(num){//expensive
const splittedNum = num.match(/../g);
const buf = new ArrayBuffer(8);
const view = new DataView(buf);
splittedNum.forEach(function (val, index) {
view.setInt8(index, parseInt(val, 16));
});
return view.getFloat64(0, 0);
}
function hexToDouble2(num){ //cheap
return Buffer.from(num, 'hex').readDoubleBE(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment