Skip to content

Instantly share code, notes, and snippets.

@g8up
Created February 14, 2017 04:20
Show Gist options
  • Save g8up/6579e021e390203e07dda7b6a054a8ea to your computer and use it in GitHub Desktop.
Save g8up/6579e021e390203e07dda7b6a054a8ea to your computer and use it in GitHub Desktop.
把一个 8位 HEX 字符串转换为浮点数
// 解码:把一个 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