Created
February 14, 2017 04:20
-
-
Save g8up/6579e021e390203e07dda7b6a054a8ea to your computer and use it in GitHub Desktop.
把一个 8位 HEX 字符串转换为浮点数
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
// 解码:把一个 8位 HEX 字符串转换为浮点数 | |
function Hex2Float( numStr ) { | |
return new Float32Array(new Uint8Array( numStr.match(/.{1,2}/g).map( function( num ) { | |
return parseInt( num, 16 ); | |
}).reverse() ).buffer )[0]; | |
}; | |
// test | |
Hex2Float("BB4E28DE");//-0.003145746421068907 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment