fix missing bin2hex()
This commit is contained in:
parent
560b737739
commit
9dde1b63d6
@ -5,7 +5,8 @@ cdef unsigned char int_to_char(unsigned char i)
|
|||||||
|
|
||||||
cpdef str hex2bin(str hexstr)
|
cpdef str hex2bin(str hexstr)
|
||||||
cpdef long bin2int(str binstr)
|
cpdef long bin2int(str binstr)
|
||||||
cpdef long hex2int(str binstr)
|
cpdef long hex2int(str hexstr)
|
||||||
|
cpdef str bin2hex(str binstr)
|
||||||
|
|
||||||
cpdef unsigned char df(str msg)
|
cpdef unsigned char df(str msg)
|
||||||
cpdef long crc(str msg, bint encode=*)
|
cpdef long crc(str msg, bint encode=*)
|
||||||
|
@ -66,6 +66,11 @@ cpdef long hex2int(str hexstr):
|
|||||||
cumul = 16*cumul + char_to_int(v_hexstr[i])
|
cumul = 16*cumul + char_to_int(v_hexstr[i])
|
||||||
return cumul
|
return cumul
|
||||||
|
|
||||||
|
@cython.boundscheck(False)
|
||||||
|
cpdef str bin2hex(str binstr):
|
||||||
|
return "{0:X}".format(int(binstr, 2))
|
||||||
|
|
||||||
|
|
||||||
@cython.boundscheck(False)
|
@cython.boundscheck(False)
|
||||||
cpdef unsigned char df(str msg):
|
cpdef unsigned char df(str msg):
|
||||||
"""Decode Downlink Format vaule, bits 1 to 5."""
|
"""Decode Downlink Format vaule, bits 1 to 5."""
|
||||||
|
@ -19,6 +19,11 @@ def bin2int(binstr):
|
|||||||
return int(binstr, 2)
|
return int(binstr, 2)
|
||||||
|
|
||||||
|
|
||||||
|
def bin2hex(binstr):
|
||||||
|
"""Convert a binary string to hexdecimal string."""
|
||||||
|
return "{0:X}".format(int(binstr, 2))
|
||||||
|
|
||||||
|
|
||||||
def df(msg):
|
def df(msg):
|
||||||
"""Decode Downlink Format value, bits 1 to 5."""
|
"""Decode Downlink Format value, bits 1 to 5."""
|
||||||
dfbin = hex2bin(msg[:2])
|
dfbin = hex2bin(msg[:2])
|
||||||
|
@ -2,7 +2,9 @@ try:
|
|||||||
from pyModeS.decoder import c_common as common
|
from pyModeS.decoder import c_common as common
|
||||||
|
|
||||||
def test_conversions():
|
def test_conversions():
|
||||||
assert common.hex2bin("6E406B") == "011011100100000001101011"
|
assert common.hex2bin("6E") == "01101110"
|
||||||
|
assert common.bin2hex("01101110") == "6E"
|
||||||
|
assert common.bin2hex("1101110") == "6E"
|
||||||
|
|
||||||
def test_crc_decode():
|
def test_crc_decode():
|
||||||
|
|
||||||
|
@ -2,7 +2,9 @@ from pyModeS import common
|
|||||||
|
|
||||||
|
|
||||||
def test_conversions():
|
def test_conversions():
|
||||||
assert common.hex2bin("6E406B") == "011011100100000001101011"
|
assert common.hex2bin("6E") == "01101110"
|
||||||
|
assert common.bin2hex("01101110") == "6E"
|
||||||
|
assert common.bin2hex("1101110") == "6E"
|
||||||
|
|
||||||
|
|
||||||
def test_crc_decode():
|
def test_crc_decode():
|
||||||
|
Loading…
Reference in New Issue
Block a user