public long toLong ( ) { byte [ ] data = getBytes ( ) ; if ( data == null || data . length <= 0 || data . length > 8 ) { // Assume that we're in a numeric context and that the user // made a typo entering a hex string. throw Error . error ( ErrorCode . X_42585 ) ; // malformed numeric constant } byte [ ] dataWithLeadingZeros = new byte [ ] { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ; int lenDiff = 8 - data . length ; for ( int j = lenDiff ; j < 8 ; ++ j ) { dataWithLeadingZeros [ j ] = data [ j - lenDiff ] ; } BigInteger bi = new BigInteger ( dataWithLeadingZeros ) ; return bi . longValue ( ) ; }
Given a sequence of bytes that would otherwise be a VARBINARY constant return a long value with the understanding that the caller has determined that this value is in a numeric context .