hex2tobin
    十六进制 to 二进制: bin(int(str,16))
    :param s:
    :return:
431841
def hex2bin(s):
    
    if len(s) % 2 != 0:
        s += '0'

    result = []
    for i in range(len(s) // 2):
        t = s[i * 2:(i + 1) * 2]
        x = dec2bin(hex2dec(t.upper()))
        padding_length = (8 - len(x) % 8) % 8
        # 每个16进制值（2个字符）进行转码，不足8个的，在前面补0
        x = '%s%s' % ('0' * padding_length, x)
        result.append(x)

    return ''.join(result)
984916
def bytes2uuid(b):
    
    if b.strip(chr(0)) == '':
        return None

    s = b.encode('hex')
    return "%s-%s-%s-%s-%s" % (s[0:8], s[8:12], s[12:16], s[16:20], s[20:])
232607
def toHex(val):
    """"""
    hex = "0123456789abcdef"
    return hex[int(val / 16)] + hex[int(val - int(val / 16) * 16)]
880647
def _convert_signed_hex(s):
    
    if s.startswith('0x') or s.startswith('-0x'):
        s = '{0:x}'.format(struct.unpack('Q', struct.pack('q', int(s, 16)))[0])
    return s.zfill(16)
914983
def bin2str(b):
    
    ret = []
    for pos in range(0, len(b), 8):
        ret.append(chr(int(b[pos:pos + 8], 2)))
    return ''.join(ret)
1331823
def gb2312_to_euc(gb2312hex):
    
    hi, lo = int(gb2312hex[:2], 16), int(gb2312hex[2:], 16)
    hi, lo = hexd(hi + 0x80), hexd(lo + 0x80)

    euc = "%s%s" % (hi, lo)
    assert isinstance(euc, bytes)
    return euc
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
500457
function binl2hex(binarray)
{
    var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
    var str = "";
    for (var i = 0; i < binarray.length * 4; i++) {
        str += hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8 + 4)) & 0xF) + hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8)) & 0xF);
    }
    return str;
}
677076
public static byte[] fromHexa(String s ) {
        byte[] ret = new byte[s.length()/2];
        for(int i=0;i<ret.length;i++){
            ret[i] = (byte) Integer.parseInt(s.substring(i*2,i*2+2),16);
        }
        return ret;
    }
835740
def dec2str(n):
    
    s = hex(int(n))[2:].rstrip('L')
    if len(s) % 2 != 0:
        s = '0' + s
    return hex2str(s)
297030
def to_s()
			hexStr = ["","","","","","","",""]
			zeroStart, consec0, finalStart, finalLen = -1,0,-1,0
			8.times do |i|
				# capture 2-byte word
				shift = 112 - 16*i
				wd = (self.addr >> shift) & 0xffff
				hexStr[i] = wd.to_s(16)
				
				# capture count of consecutive zeros
				if (wd == 0)
					if (zeroStart == -1)
						zeroStart = i
					end
					consec0 += 1
				end
				
				# test for longest consecutive zeros when non-zero encountered or we're at the end
				if (wd != 0 || i == 7)
					if (consec0 > finalStart+finalLen-1)
						finalStart = zeroStart
						finalLen = consec0
					end
					zeroStart = -1
					consec0 = 0
				end
			end
			
			# compress if we've found a series of 0 words in a row
			if (finalStart != -1)
				head = hexStr[0,finalStart].join(":")
				tailStart = finalStart + finalLen 
				tail = hexStr[tailStart..7].join(":")
				return head + "::" + tail
			end
			return hexStr.join(":")
		end
591207
def rh45(msg):
    
    d = hex2bin(data(msg))
    if d[38] == '0':
        return None
    rh = bin2int(d[39:51]) * 16
    return rh
1017556
function binToHex(binArray){
        var hexString = "0123456789abcdef",
            str = "",
            i;

        for(i = 0; i < binArray.length * 4; i++){
            str += hexString.charAt((binArray[i >> 2] >> ((3 - i % 4) * 8 + 4)) & 0xF) +
                    hexString.charAt((binArray[i >> 2] >> ((3 - i % 4) * 8  )) & 0xF);
        }

        return str;
    }
148338
def intToBin(i):
    
    # devide in two parts (bytes)
    i1 = i % 256
    i2 = int(i / 256)
    # make string (little endian)
    return chr(i1) + chr(i2)
105965
def hum44(msg):
    
    d = hex2bin(data(msg))

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

    hm = bin2int(d[50:56]) * 100.0 / 64    # %

    return round(hm, 1)
881002
def hex_to_f(h)
      h = (h[1..-1]).chars.each_slice(2).map(&:join)
      a = []

      h.each do |el|
        a.push(el.to_i(16))
      end

      a.push(255)
      return to_f(a)
    end
672190
function toHex(binary, start, end) {
  var hex = "";
  if (end === undefined) {
    end = binary.length;
    if (start === undefined) start = 0;
  }
  for (var i = start; i < end; i++) {
    var byte = binary[i];
    hex += String.fromCharCode(nibbleToCode(byte >> 4)) +
           String.fromCharCode(nibbleToCode(byte & 0xf));
  }
  return hex;
}