Alex Martelli在该问题中给出的答案非常简单-您可以将其简化为:
>>> import struct>>> >>> >>> def floatToBits(f):... s = struct.pack('>f', f)... return struct.unpack('>l', s)[0]... ... >>> floatToBits(173.3125)1127043072>>> hex(_)'0x432d5000'
您可以将 *** 作顺序反转为往返:
>>> def bitsToFloat(b):... s = struct.pack('>l', b)... return struct.unpack('>f', s)[0]>>> bitsToFloat(0x432d5000)173.3125
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)