simplify hex2bin()

pull/3/head
Junzi Sun 9 years ago
parent 2e3ceed0b0
commit 818207a4d8

@ -42,11 +42,10 @@ MODES_CHECKSUM_TABLE = [
def hex2bin(hexstr): def hex2bin(hexstr):
"""Convert a hexdecimal string to binary string, with zero fillings. """ """Convert a hexdecimal string to binary string, with zero fillings. """
length = len(hexstr) * 4 scale = 16
msgbin = bin(int(hexstr, 16))[2:] num_of_bits = len(hexstr) * math.log(scale, 2)
while ((len(msgbin)) < length): binstr = bin(int(hexstr, scale))[2:].zfill(int(num_of_bits))
msgbin = '0' + msgbin return binstr
return msgbin
def bin2int(binstr): def bin2int(binstr):
@ -230,6 +229,7 @@ def cpr2position(cprlat0, cprlat1, cprlon0, cprlon1, t0, t1):
return lat, lon return lat, lon
def get_velocity(msg): def get_velocity(msg):
"""Calculate the speed, heading, and vertical rate""" """Calculate the speed, heading, and vertical rate"""

Loading…
Cancel
Save