Java implements hexadecimal to floating point number

1) Use the conversion between BigInteger and hexadecimal

// 16进制转大数值
new BigInteger("419e6666", 16);

2) Use the Float.intBitsToFloat() method

//参数为 int 类型的二进制、八进制、十六进制
Float.intBitsToFloat(1100899942)

This method supports signed conversion, sample code and running effect:

Float f = Float.intBitsToFloat(new BigInteger("419e6666", 16).intValue());
System.out.println(f);

419e6666 The result of converting a hexadecimal string to a floating point number is: 19.8

insert image description here

Guess you like

Origin blog.csdn.net/qq_40042416/article/details/127800609
Recommended