Created
June 29, 2021 12:50
-
-
Save atksh/312eddde53e959d4f34d01ce5a4a8970 to your computer and use it in GitHub Desktop.
convert IEEE-111073-16bit-sfloat to float
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| def to_float_from_11073_16bit_sfloat(data): | |
| tmp = int.from_bytes(data, "little") | |
| uint16val = np.array([tmp], dtype=np.uint16) | |
| tmp = bin(uint16val[0] & 0xfff) | |
| mantissa = int(tmp, 0) | |
| tmp = np.right_shift(uint16val, 12) | |
| exponent = int(bin(tmp[0]), 0) | |
| ret = round(mantissa * pow(10, exponent), 1) | |
| return ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment