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 ; }
Given a string of hex digits produce a long value assuming a 2 s complement representation .