如何在python中获取浮点数的十六进制值?
浮点数的十六进制值
要获取浮点数的十六进制值,我们使用–float.hex()方法,它接受浮点值并以字符串格式返回其十六进制值。
语法:
float.hex(number)
Parameter(s):number-要转换为十六进制的浮点值。
返回值:str–以字符串格式返回数字的十六进制值。
示例
Input:
num = 10.23
print("hex value of ", num, " is = ", float.hex(num))
Output:
hex value of 10.23 is = 0x1.475c28f5c28f6p+3Python代码获取给定浮点数的十六进制值
#python代码演示示例
# of float.hex() function
num = 0.0
print("hex value of ", num, " is = ", float.hex(num))
num = 10.23
print("hex value of ", num, " is = ", float.hex(num))
num = -10.23
print("hex value of ", num, " is = ", float.hex(num))输出结果
hex value of 0.0 is = 0x0.0p+0 hex value of 10.23 is = 0x1.475c28f5c28f6p+3 hex value of -10.23 is = -0x1.475c28f5c28f6p+3