Converts a Long integer (or hex string) to hex format padded with zeroes for hashing
    :param {Long integer|String} long_int Number or string to pad.
    :return {String} Padded hex string.
354685
def pad_hex(long_int):
    
    if not isinstance(long_int, six.string_types):
        hash_str = long_to_hex(long_int)
    else:
        hash_str = long_int
    if len(hash_str) % 2 == 1:
        hash_str = '0%s' % hash_str
    elif hash_str[0] in '89ABCDEFabcdef':
        hash_str = '00%s' % hash_str
    return hash_str
944591
def bigint_to_string(val):
    
    if isinstance(val, _NUMBERS) and not abs(val) <= 2**53-1:
        return str(val)
    return val
21743
def _num_to_string(self, number, pad_to_length=None):
        
        output = ""
        while number:
            number, digit = divmod(number, self._alpha_len)
            output += self._alphabet[digit]
        if pad_to_length:
            remainder = max(pad_to_length - len(output), 0)
            output = output + self._alphabet[0] * remainder
        return output
1091660
def b58decode(s, errors='strict'):
    ""
    if not s:
        return (b'', 0)

    # Convert the string to an integer
    n = 0
    for c in s:
        n *= 58
        if c not in b58digits:
            raise InvalidBase58Error(u"character %r is not a valid base58 "
                u"character" % c)
        digit = b58digits.index(c)
        n += digit

    # Convert the integer to bytes
    res = BigInteger(n).serialize((n.bit_length()+7)//8 or 1)

    # Add padding back.
    pad = 0
    for c in s[:-1]:
        if c == b58digits[0]: pad += 1
        else: break
    return (b'\x00' * pad + res, len(s))
834126
public static long hexDigitsToLong(String hexDigits) throws SQLParser.Exception {

        // BigInteger.longValue() will truncate to the lowest 64 bits,
        // so we need to explicitly check if there's too many digits.
        if (hexDigits.length() > 16) {
            throw new SQLParser.Exception("Too many hexadecimal digits for BIGINT value");
        }

        if (hexDigits.length() == 0) {
            throw new SQLParser.Exception("Zero hexadecimal digits is invalid for BIGINT value");
        }

        // The method
        //   Long.parseLong(<digits>, <radix>);
        // Doesn't quite do what we want---it expects a '-' to
        // indicate negative values, and doesn't want the sign bit set
        // in the hex digits.
        //
        // Once we support Java 1.8, we can use Long.parseUnsignedLong(<digits>, 16)
        // instead.

        long val = new BigInteger(hexDigits, 16).longValue();
        return val;
    }
859076
private long toLong(byte[] data)
    {
        if (data == null || data.length != 8)
            return 0x0;
        // ----------
        return (long) (
        // (Below) convert to longs before shift because digits
        // are lost with ints beyond the 32-bit limit
        (long) (0xff & data[0]) << 56 | (long) (0xff & data[1]) << 48 | (long) (0xff & data[2]) << 40
                | (long) (0xff & data[3]) << 32 | (long) (0xff & data[4]) << 24 | (long) (0xff & data[5]) << 16
                | (long) (0xff & data[6]) << 8 | (long) (0xff & data[7]) << 0);
    }
800938
protected static long fromHex(String hex) {
        long value = 0;
        for (int i = 0; i < hex.length(); i++)
            value = (value << 4) | digit(hex.charAt(i), 16);

        return value;
    }

    protected static String encodeULong(long value) {
        return String.format("%016x", value);
    }

    protected static String encodeUInt(int value) {
        return String.format("%08x", value);
    }

    protected static int normalizeFloat(float value) {
        int intBits = floatToIntBits(value);
        if (intBits < 0)
            return ~intBits;
        else
            return intBits ^ Integer.MIN_VALUE;
    }

    protected static float denormalizeFloat(int value) {
        if (value > 0)
            return intBitsToFloat(~value);
        else
            return intBitsToFloat(value ^ Integer.MIN_VALUE);
    }

    protected static long normalizeDouble(double value) {
        long longBits = doubleToRawLongBits(value);
        if (longBits < 0)
            return ~longBits;
        else
            return longBits ^ Long.MIN_VALUE;
    }

    protected static double denormalizeDouble(long value) {
        if (value > 0)
            return longBitsToDouble(~value);
        else
            return longBitsToDouble(value ^ Long.MIN_VALUE);
    }

    public static byte[] reverse(byte[] bytes) {
        byte[] result = new byte[bytes.length];

        for (int i = 0; i < bytes.length; i++)
            result[i] = (byte) (0xff - (0xff & bytes[i]));

        return result;
    }
}
1208895
def serialize_number(x, fmt=SER_BINARY, outlen=None):
    
    ret = b''
    if fmt == SER_BINARY:
        while x:
            x, r = divmod(x, 256)
            ret = six.int2byte(int(r)) + ret
        if outlen is not None:
            assert len(ret) <= outlen
            ret = ret.rjust(outlen, b'\0')
        return ret
    assert fmt == SER_COMPACT
    while x:
        x, r = divmod(x, len(COMPACT_DIGITS))
        ret = COMPACT_DIGITS[r:r + 1] + ret
    if outlen is not None:
        assert len(ret) <= outlen
        ret = ret.rjust(outlen, COMPACT_DIGITS[0:1])
    return ret
120375
function (hexString) {
    if (hexString.slice(0, 2) === '0x') {
      hexString = hexString.slice(2)
    }
    var integers = []
    for (var i = 0; i < hexString.length; i += 2) {
      integers.push(parseInt(hexString.slice(i, i + 2), 16))
    }
    return integers
  }
301676
def i2osp(self, long_integer, block_size):
        ''
        hex_string = '%X' % long_integer
        if len(hex_string) > 2 * block_size:
            raise ValueError('integer %i too large to encode in %i octets' % (long_integer, block_size))
        return a2b_hex(hex_string.zfill(2 * block_size))
532834
public static String intToHex(int number, int hexSize) {
        String tmp = Integer.toHexString(number & 0xFF);
        while (tmp.length() < hexSize) {
            tmp = "0" + tmp;
        }
        return tmp;
    }
627429
def _long2bytes(n, blocksize=0):
    

    # After much testing, this algorithm was deemed to be the fastest.
    s = ''
    pack = struct.pack
    while n > 0:
        ### CHANGED FROM '>I' TO '<I'. (DCG)
        s = pack('<I', n & 0xffffffffL) + s
        ### --------------------------
        n = n >> 32

    # Strip off leading zeros.
    for i in range(len(s)):
        if s[i] <> '\000':
            break
    else:
        # Only happens when n == 0.
        s = '\000'
        i = 0

    s = s[i:]

    # Add back some pad bytes. This could be done more efficiently
    # w.r.t. the de-padding being done above, but sigh...
    if blocksize > 0 and len(s) % blocksize:
        s = (blocksize - len(s) % blocksize) * '\000' + s

    return s
255285
function toHexString(buffer, options) {
        options = options || {};
        var prefix = options.prefix || '', digits, idx;

        if ((options.format || 'BE') !== 'BE') {
            _reverseBuffer(buffer);
        }

        digits = buffer.toString('hex');
        idx = _lastHeadIndex(digits, '0');

        // if there are only 0's use the last digit
        idx = idx >= 0 ? idx : digits.length - 1;

        return prefix + _pad(
            _split(digits.slice(idx), options.groupsize, options.delimiter), prefix, options.padstr, options.size);
    }
549872
def decode_int(v):
    """"""
    if len(v) > 0 and (v[0] == b'\x00' or v[0] == 0):
        raise Exception("No leading zero bytes allowed for integers")
    return big_endian_to_int(v)
1178613
def __convertLongToString(self, iValue):
        
        string = ''
        strValue = str(hex(iValue))

        string = strValue.lstrip('0x')
        string = string.rstrip('L')

        return string
48138
def pad_hex(value, bit_size):
    
    value = remove_0x_prefix(value)
    return add_0x_prefix(value.zfill(int(bit_size / 4)))
1067836
def to_hex(
    primitive: Primitives = None, hexstr: HexStr = None, text: str = None
) -> HexStr:
    
    if hexstr is not None:
        return HexStr(add_0x_prefix(hexstr.lower()))

    if text is not None:
        return HexStr(encode_hex(text.encode("utf-8")))

    if is_boolean(primitive):
        return HexStr("0x1") if primitive else HexStr("0x0")

    if isinstance(primitive, (bytes, bytearray)):
        return HexStr(encode_hex(primitive))
    elif is_string(primitive):
        raise TypeError(
            "Unsupported type: The primitive argument must be one of: bytes,"
            "bytearray, int or bool and not str"
        )

    if is_integer(primitive):
        return HexStr(hex(cast(int, primitive)))

    raise TypeError(
        "Unsupported type: '{0}'.  Must be one of: bool, str, bytes, bytearray"
        "or int.".format(repr(type(primitive)))
    )