Skip to content

Commit

Permalink
unstruct integer
Browse files Browse the repository at this point in the history
  • Loading branch information
redsuns-chan committed Jul 29, 2022
1 parent 58e89ba commit f734b28
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion hex-to-float-covertor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# hex to float convertor
# author: RedSuns Chan

from cmath import isnan
from os import path, stat
import struct
import sys
Expand All @@ -20,7 +21,10 @@ def main(file_path: str, big_endian: bool):
le_bytes = bytearray.fromhex(n)
if big_endian == False:
le_bytes.reverse()
converted.append(struct.unpack('!f', le_bytes)[0])
float_num = struct.unpack('!f', le_bytes)[0]
if isnan(float_num):
float_num = struct.unpack('!i', le_bytes)[0]
converted.append(float_num)
i += 8
f.close()
print(converted)
Expand Down

0 comments on commit f734b28

Please sign in to comment.