On Wed, Mar 11, 2009 at 9:54 AM, Allahbaksh Mohammedali Asadullah <[email protected]> wrote: > Hi all, > Can any one explain How function integer2String works. > > public static int int2sortableStr(int val, char[] out, int offset) { > > val += Integer.MIN_VALUE;
This maps MIN_VALUE to 0 and MAX_VALUE to 0xffffffff, making the bits sort lexicographically the same as the full integer range. It's the same as flipping the sign bit. > out[offset++] = (char)(val >>> 24); > out[offset++] = (char)((val >>> 12) & 0x0fff); > out[offset++] = (char)(val & 0x0fff); This chops up the bits to fit in char sized pieces to make a string, avoiding invalid character ranges. -Yonik http://www.lucidimagination.com --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
