小数进制转化 @ Python

# -*- coding: utf8 -*-
import ctypes
def h2f(s):
    cp = ctypes.pointer(ctypes.c_longlong(s))
    fp = ctypes.cast(cp, ctypes.POINTER(ctypes.c_double))
    return fp.contents.value
def f2h(s):
    fp = ctypes.pointer(ctypes.c_double(s))
    cp = ctypes.cast(fp, ctypes.POINTER(ctypes.c_longlong))
    return hex(cp.contents.value)
print(f2h(34.4536))
print(h2f(0x40413a0f9096bb99))

你可能感兴趣的:(python)