Skip to content

Instantly share code, notes, and snippets.

@sdbakker
Last active April 4, 2018 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdbakker/342e2fa00fbbea826ec132eb61cacd15 to your computer and use it in GitHub Desktop.
Save sdbakker/342e2fa00fbbea826ec132eb61cacd15 to your computer and use it in GitHub Desktop.
S7 -> IRC5 GI/GO conversions
"""
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