converting a float to bytearray or int

https://stackoverflow.com/questions/36893206/converting-a-float-to-bytearray/36894176

>>> value = 3.5e-43 >>> ba = bytearray(struct.pack("f", value)) >>> print([ "0x%02x" % b for b in ba ]) ['0xfa', '0x00', '0x00', '0x00']


0xfa is actually 250

posted on 2021-12-22 10:19  cdekelon  阅读(23)  评论(0)    收藏  举报

导航