Last active
April 4, 2018 09:54
-
-
Save sdbakker/342e2fa00fbbea826ec132eb61cacd15 to your computer and use it in GitHub Desktop.
S7 -> IRC5 GI/GO conversions
This file contains 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
""" | |
No need for little / big endian byte swapping | |
this is already done by the group input/output ordening | |
GI.. expect byte array | |
..GI return byte array | |
""" | |
import struct | |
def GIToFloat(gi): | |
xx = gi.to_bytes(4, 'little') | |
return struct.unpack('f', xx)[0] | |
def FloatToGO(f): | |
xx = struct.pack('f', f) | |
return int.from_bytes(xx, 'little') | |
def GIToInt16(gi): | |
return int.from_bytes(gi, 'little') | |
def Int16ToGO(int16): | |
return int16.to_bytes(2, 'little') | |
def GIToInt32(gi): | |
return int.from_bytes(gi, 'little') | |
def Int32ToGO(int32): | |
return int32.to_bytes(4, 'little') | |
if __name__ == '__main__': | |
print('\n') | |
GI = b'\x00\x00\xa0B' | |
x = GIToFloat(GI) | |
print("GI -> Float: %s -> %f" % (GI, x)) | |
GO = FloatToGO(x) | |
print("Float -> GO: %f -> %s" % (x, GO)) | |
GI = b'\x00\x00\xa0B' | |
x = GIToInt32(GI) | |
print("DWord -> Int32: %s -> %d" % (GI, x)) | |
GO = Int32ToGO(x) | |
print("Int32 -> DWord: %d -> %s" % (x, GO)) | |
GI = b'\xa0B' | |
x = GIToInt16(GI) | |
print("Word -> Int16: %s -> %d" % (GI, x)) | |
GO = Int16ToGO(x) | |
print("Int16 -> Word: %d -> %s" % (x, GO)) | |
print('\n') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment