bit manipulation - A question in java.lang.Integer internal code -


while looking in code of method:

integer.tohexstring

i found following code :

public static string tohexstring(int i) {     return tounsignedstring(i, 4); }  private static string tounsignedstring(int i, int shift) {     char[] buf = new char[32];     int charpos = 32;     int radix = 1 << shift;     int mask = radix - 1;     {         buf[--charpos] = digits[i & mask];         >>>= shift;     } while (i != 0);      return new string(buf, charpos, (32 - charpos)); } 

the question is, in tounsignedstring, why create char arr of 32 chars?

32 characters how need represent int in binary (base-2, shift of 1, used tobinarystring).

it sized exactly, guess has never made business sense attempt optimisation.


Comments

Popular posts from this blog

Delphi Wmi Query on a Remote Machine -