Skip to content

Instantly share code, notes, and snippets.

@clydebarrow
Created December 21, 2022 02:19
Show Gist options
  • Save clydebarrow/23b59623755f9b6674829d35f2e45984 to your computer and use it in GitHub Desktop.
Save clydebarrow/23b59623755f9b6674829d35f2e45984 to your computer and use it in GitHub Desktop.
Convert VH aircraft registration code to ICAO mode-S identifier
import sys
def getVal(ch):
if ch >= 'A' and ch <= 'Z':
return ord(ch) - ord('A')
if ch >= '0' and ch <= '9':
return ord(ch) - ord('0') + 26
return -1
if len(sys.argv) <= 1:
print ('Usage: modescode AAA')
sys.exit()
code = sys.argv[1].upper()
if (len(code) != 3) or (not code.isalnum()):
print ('Argument must be three alphanumeric characters')
sys.exit()
total = 0x7C0000
total += getVal(code[2])
total += getVal(code[1]) * 36
total += getVal(code[0]) * 36 * 36
print('{} encoded in hex is {:X}'.format( code, total))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment