Skip to content

Instantly share code, notes, and snippets.

@cwacek
Last active December 23, 2015 09:19
Show Gist options
  • Save cwacek/6613735 to your computer and use it in GitHub Desktop.
Save cwacek/6613735 to your computer and use it in GitHub Desktop.
Decode SAFEST Coordinate
c = "0302A3DC4081535367C002B9D21D0E7379408F39625AD67A70400000000000000000D43E85729743E63F"
import struct
decoded = c.decode('hex')
dim, vartype = struct.unpack('=bb', decoded[:2])
fmt = 'f' if vartype == 1 else 'd'
fmtsz = 4 if fmt == 'f' else 8
coords = struct.unpack_from('{0}{1}'.format(dim, fmt),
decoded[2:])
height, error = struct.unpack_from('{0}{1}'.format(2, fmt),
decoded[2:], dim * fmtsz)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment