Created
October 11, 2020 21:37
-
-
Save supernovaplus/c0d90cca34e6998ba8d5bc7b51a6fa31 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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