Jan-11-2021, 07:42 AM
(Nov-16-2020, 12:29 PM)Gribouillis Wrote: You need something more systematic, perhaps along the lines ofHi Sir, I know this is long due and I am so sorry for that, but is there a way to encode and decode the latitude and longitude of the GPS in such a way that it transmits lesser bits?
def encode(pattern, numbers): result = 0 for size, n in zip(pattern, numbers): result = (result << size) + n return result def decode(pattern, n): result = [] for size in reversed(pattern): n, r = divmod(n, 1 << size) result.append(r) return tuple(reversed(result)) if __name__ == '__main__': pat_lat = (1, 3, 4 ,4, 4, 4, 4) pat_long = (1, 3, 3, 4, 4, 3, 4, 4) data = (1, 2, 5, 5, 7, 6, 3) n = encode(pat_lat, data) print(data) print(bin(n)) print(decode(pat_lat, n))
Output:(1, 2, 5, 5, 7, 6, 3) 0b101001010101011101100011 (1, 2, 5, 5, 7, 6, 3)