Decode a hex nibble. E.g. '3' -> 3 and 'F' -> 15.
177156
private static int decodeHex(final char c) {
    if (c < '0') {
      return INVALID;
    }
    if (c <= '9') {
      return c - '0';
    }
    if (c < 'A') {
      return INVALID;
    }
    if (c <= 'F') {
      return c - 'A' + 10;
    }
    if (c < 'a') {
      return INVALID;
    }
    if (c <= 'f') {
      return c - 'a' + 10;
    }
    return INVALID;
  }
475844
def _dehex(s):
    """"""
    import re
    import binascii

    # Remove all non-hexadecimal digits
    s = re.sub(br'[^a-fA-F\d]', b'', s)
    # binscii.unhexlify works in Python 2 and Python 3 (unlike
    # thing.decode('hex')).
    return binascii.unhexlify(s)
1086202
def rgb2hex(rgb):
    
    if len(rgb) > 3:
        rgb = rgb[:-1]
    return "#{0:02x}{1:02x}{2:02x}".format(*(int(v*255) for v in rgb))
1080115
def format_hex(i, num_bytes=4, prefix='0x'):
    
    prefix = str(prefix or '')
    i = int(i or 0)
    return prefix + '{0:0{1}x}'.format(i, num_bytes)
1065171
def hex_to_rgb(hexx):
    
    h = hexx.strip('#')
    l = len(h)

    return tuple(int(h[i:i+l//3], 16) for i in range(0, l, l//3))
154779
def _decode_fname(self):
        """"""
        self.fname = self.fname[:self.fname.find('\0')]
        self.fname = self.fname.replace('\\', '/')
339958
def fw_int_to_hex(*args):
    
    return binascii.hexlify(
        struct.pack('<{}H'.format(len(args)), *args)).decode('utf-8')
859578
function toHex(c) {
    var m = c.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/)
    return (m ? rgb(m[1], m[2], m[3]) : c)
      .replace(/#(\w)(\w)(\w)$/, '#$1$1$2$2$3$3') // short skirt to long jacket
  }
58037
def decode(C):
    
    C = array(C)

    flatten = False
    if len(C.shape) == 1:
        flatten = True
        C = C.reshape(1, -1)

    if C.shape[1] != msg_size:
        raise ValueError('Data must be shaped as (7, ) or (-1, 7)')

    if 1 in dot(H, C.T).T % 2:
        raise ValueError('Incorrect code given as input.')

    B = C[:, data_bits]

    if flatten:
        B = B.flatten()

    return B
232607
def toHex(val):
    """"""
    hex = "0123456789abcdef"
    return hex[int(val / 16)] + hex[int(val - int(val / 16) * 16)]
928410
def _decode_data(self, data):
        """"""
        self.major = data[0]

        if data[1] is 0xff:
            self.minor = data[1]
        elif data[1] <= 0x99:
            self.minor = int(data[1:2].tostring().decode('bcd+'))
        else:
            raise DecodingError()
324537
function decodeSample_(nibble) {
  /** @type {number} */
  let difference = 0;
  if (nibble & 4) {
    difference += decoderStep_;
  }
  if (nibble & 2) {
    difference += decoderStep_ >> 1;
  }
  if (nibble & 1) {
    difference += decoderStep_ >> 2;
  }
  difference += decoderStep_ >> 3;
  if (nibble & 8) {
    difference = -difference;
  }
  decoderPredicted_ += difference;
  if (decoderPredicted_ > 32767) {
    decoderPredicted_ = 32767;
  } else if (decoderPredicted_ < -32767) {
    decoderPredicted_ = -32767;
  }
  updateDecoder_(nibble);
  return decoderPredicted_;
}
239726
def decode_int(self, str):
        
        n = 0
        for c in str:
            n = n * self.BASE + self.ALPHABET_REVERSE[c]
        return n
245296
def hex2bin(hexstr):
    
    num_of_bits = len(hexstr) * 4
    binstr = bin(int(hexstr, 16))[2:].zfill(int(num_of_bits))
    return binstr
1159596
def rgb_to_hexa(*args):
    """"""
    if len(args) == 3:
        return ("#%2.2x%2.2x%2.2x" % tuple(args)).upper()
    elif len(args) == 4:
        return ("#%2.2x%2.2x%2.2x%2.2x" % tuple(args)).upper()
    else:
        raise ValueError("Wrong number of arguments.")
1010266
def calculate_hex(hex_string):
        """"""
        hex_conv = hex_string.split(':')
        converted_hex = (int(hex_conv[0], 16) + int(hex_conv[1], 16))/8192

        return converted_hex
654848
def decode_string(data, encoding='hex'):
    '''
    
    '''
    if six.PY2:
        return data.decode(encoding)
    else:
        return codecs.decode(data.encode('ascii'), encoding)