我用来转换hexadecimals > float pointers
的代码:
from ctypes import *
def convert(s):
i = int(s, 16) # convert from hex to a Python int
cp = pointer(c_int(i)) # make this into a c integer
fp = cast(cp, POINTER(c_float)) # cast the int pointer to a float pointer
return fp.contents.value # dereference the pointer, get the float
print convert("41973333") # returns 1.88999996185302734375E1
print convert("41995C29") # returns 1.91700000762939453125E1
print convert("470FC614") # returns 3.6806078125E4
但我不确定如何才能扭转这种影响。在
我试图从float pointer > hexadecimal
开始,而不是hexadecimal > float pointer
。在
您可以使用
struct
将十六进制转换为浮点将提供:
^{pr2}$你也做同样的事,但是向后:
代码:
输出:
^{pr2}$相关问题 更多 >
编程相关推荐