bin2hex
    二进制 to 十六进制: hex(int(str,2))
    :param s:
    :return:
977422
def bin2hex(s):
    
    padding_length = (8 - len(s) % 8) % 8
    # 从前往后解码，不足8个的，在后面补0
    encode_str = '%s%s' % (s, '0' * padding_length)
    # 解码后是 0xab1234，需要去掉前面的 0x
    return hex(int(encode_str, 2))[2:].rstrip('L')
158344
def hex(self):
        """"""
        addrstr = '000000'
        if self.addr is not None:
            addrstr = binascii.hexlify(self.addr).decode()
        return addrstr
416195
def i2osp(x, x_len):
    '''
    '''
    if x > 256**x_len:
        raise exceptions.IntegerTooLarge
    h = hex(x)[2:]
    if h[-1] == 'L':
        h = h[:-1]
    if len(h) & 1 == 1:
        h = '0%s' % h
    x = binascii.unhexlify(h)
    return b'\x00' * int(x_len-len(x)) + x
1368719
def dec2bin(s):
    
    if not isinstance(s, int):
        num = int(s)
    else:
        num = s
    mid = []
    while True:
        if num == 0:
            break
        num, rem = divmod(num, 2)
        mid.append(base[rem])

    return ''.join([str(x) for x in mid[::-1]])
1065159
def rgb_2_hex(self, r, g, b):
        
        return "#{:02X}{:02X}{:02X}".format(int(r * 255), int(g * 255), int(b * 255))
180764
def _readhex(self, length, start):
        """"""
        if length % 4:
            raise InterpretError("Cannot convert to hex unambiguously - "
                                           "not multiple of 4 bits.")
        if not length:
            return ''
        s = self._slice(start, start + length).tobytes()
        try:
            s = s.hex() # Available in Python 3.5
        except AttributeError:
            # This monstrosity is the only thing I could get to work for both 2.6 and 3.1.
            # TODO: Is utf-8 really what we mean here?
            s = str(binascii.hexlify(s).decode('utf-8'))
        # If there's one nibble too many then cut it off
        return s[:-1] if (length // 4) % 2 else s
366110
def hex2dec(s):
    
    if not isinstance(s, str):
        s = str(s)
    return int(s.upper(), 16)
591207
def rh45(msg):
    
    d = hex2bin(data(msg))
    if d[38] == '0':
        return None
    rh = bin2int(d[39:51]) * 16
    return rh
385007
def n2s(n):
    
    s = hex(n)[2:].rstrip("L")
    if len(s) % 2 != 0:
        s = "0" + s
    return s.decode("hex")
291438
def crc_ihex(hexstr):
    

    crc = sum(bytearray(binascii.unhexlify(hexstr)))
    crc &= 0xff
    crc = ((~crc + 1) & 0xff)

    return crc
659862
public static byte[] hex2byte(String hex) {
		byte[] ret = new byte[8];
		byte[] tmp = hex.getBytes();
		for (int i = 0; i < 8; i++) {
			ret[i] = uniteBytes(tmp[i * 2], tmp[i * 2 + 1]);
		}
		return ret;
	}
346966
def binary_value(self):
        
        str_raw_value = str(self.raw_value)
        if len(str_raw_value) % 2 == 1:
            str_raw_value = '0' + str_raw_value

        return binascii.unhexlify(str_raw_value)
726621
def hex2termhex(hexval: str, allow_short: bool = False) -> str:
    
    return rgb2termhex(*hex2rgb(hexval, allow_short=allow_short))
329804
def unhex(inp):
    ''''''
    res = inp.split(r'\x')
    for i in xrange(1, len(res)):
        item = res[i]
        try:
            res[i] = _hextochr[item[:2]] + item[2:]
        except KeyError:
            res[i] = '%' + item
        except UnicodeDecodeError:
            res[i] = unichr(int(item[:2], 16)) + item[2:]
    return ''.join(res)
105436
def rgb2hex(r: int, g: int, b: int) -> str:
    
    return '{:02x}{:02x}{:02x}'.format(r, g, b)
752658
def deserialize_number(s, fmt=SER_BINARY):
    
    ret = gmpy.mpz(0)
    if fmt == SER_BINARY:
        if isinstance(s, six.text_type):
            raise ValueError(
                "Encode `s` to a bytestring yourself to" +
                " prevent problems with different default encodings")
        for c in s:
            ret *= 256
            ret += byte2int(c)
        return ret
    assert fmt == SER_COMPACT
    if isinstance(s, six.text_type):
        s = s.encode('ascii')
    for c in s:
        ret *= len(COMPACT_DIGITS)
        ret += R_COMPACT_DIGITS[c]
    return ret
642558
def gs50(msg):
    
    d = hex2bin(data(msg))

    if d[23] == '0':
        return None

    spd = bin2int(d[24:34]) * 2    # kts
    return spd