I am working on decoding gsm 7 bit and found this piece of code on this site from a user called noiam.
def gsm7bitdecode(f):
f = ''.join(["{0:08b}".format(int(f[i:i+2], 16)) for i in range(0, len(f), 2)][::-1])
return ''.join([chr(int(f[::-1][i:i+7][::-1], 2)) for i in range(0, len(f), 7)])
I have come to a crossroads in my decode as it doesn't help decode a message with an offset.
If someone could help explain what that piece of code is doing and how to alter it to decode messages with an offset of 1/2/3/etc (both forwards and backwards) then you would be helping me out a lot.
Thanks in advance!
It's string parsing in an exceptionally tight/efficient implementation. Below is what it could look like expanded out:
range docs: http://pythoncentral.io/pythons-range-function-explained/
extended slice docs: https://docs.python.org/release/2.3.5/whatsnew/section-slices.html
int docs: https://docs.python.org/2/library/functions.html#int
join docs: https://docs.python.org/2/library/stdtypes.html#str.join