Get the “bits” of a float in Python?

后端 未结 3 1307
旧时难觅i
旧时难觅i 2020-12-17 17:39

I am looking for the Python equivalent of Java\'s Float.floatToBits.

I found this Python: obtain & manipulate (as integers) bit patterns of floats

3条回答
  •  青春惊慌失措
    2020-12-17 17:54

    >>> import ctypes
    >>> f = ctypes.c_float(173.3125)
    >>> ctypes.c_int.from_address(ctypes.addressof(f)).value
    1127043072
    

提交回复
热议问题