| 25 | # convert string to hex function taken from: |
| 26 | # https://stackoverflow.com/questions/1592158/convert-hex-to-float # |
| 27 | def convert(s, datatype="np.float32"): |
| 28 | i = int(s, 16) # convert from hex to a Python int |
| 29 | if (datatype == "np.float64"): |
| 30 | cp = pointer(c_longlong(i)) # make this into a c long long integer |
| 31 | fp = cast(cp, POINTER(c_double)) # cast the int pointer to a double pointer |
| 32 | else: |
| 33 | cp = pointer(c_int(i)) # make this into a c integer |
| 34 | fp = cast(cp, POINTER(c_float)) # cast the int pointer to a float pointer |
| 35 | |
| 36 | return fp.contents.value # dereference the pointer, get the float |
| 37 | |
| 38 | str_to_float = np.vectorize(convert) |
| 39 | |