[Python] how to transform bytes to float with python?

Discussão em 'Python' iniciado por Stack, Junho 3, 2025.

  1. Stack

    Stack Membro Participativo

    I got a binary file written in java.I want to read the file with python,and convert every 4 bytes to a float.

    the first 4 bytes is bce9 1165,but I read it is b'\xbc\xe9\x11e' by the code

    with open(filename, "rb+") as f:
    f.read(4)


    it's different!

    Then I convert it by struct.unpack('f',data1).but I got the wrong float. the wrong float is 4.30659236383095e+22. but it's truly -0.028450677 so how to decode it?

    Continue reading...

Compartilhe esta Página