359 formatUnsignedLong(val, shift, buf, 0, chars); |
359 formatUnsignedLong(val, shift, buf, 0, chars); |
360 return new String(buf, true); |
360 return new String(buf, true); |
361 } |
361 } |
362 |
362 |
363 /** |
363 /** |
364 * Format a long (treated as unsigned) into a character buffer. |
364 * Format a long (treated as unsigned) into a character buffer. If |
|
365 * {@code len} exceeds the formatted ASCII representation of {@code val}, |
|
366 * {@code buf} will be padded with leading zeroes. |
|
367 * |
365 * @param val the unsigned long to format |
368 * @param val the unsigned long to format |
366 * @param shift the log2 of the base to format in (4 for hex, 3 for octal, 1 for binary) |
369 * @param shift the log2 of the base to format in (4 for hex, 3 for octal, 1 for binary) |
367 * @param buf the character buffer to write to |
370 * @param buf the character buffer to write to |
368 * @param offset the offset in the destination buffer to start at |
371 * @param offset the offset in the destination buffer to start at |
369 * @param len the number of characters to write |
372 * @param len the number of characters to write |
370 * @return the lowest character location used |
373 */ |
371 */ |
374 static void formatUnsignedLong(long val, int shift, char[] buf, int offset, int len) { |
372 static int formatUnsignedLong(long val, int shift, char[] buf, int offset, int len) { |
375 // assert shift > 0 && shift <=5 : "Illegal shift value"; |
373 int charPos = len; |
376 // assert offset >= 0 && offset < buf.length : "illegal offset"; |
|
377 // assert len > 0 && (offset + len) <= buf.length : "illegal length"; |
|
378 int charPos = offset + len; |
374 int radix = 1 << shift; |
379 int radix = 1 << shift; |
375 int mask = radix - 1; |
380 int mask = radix - 1; |
376 do { |
381 do { |
377 buf[offset + --charPos] = Integer.digits[((int) val) & mask]; |
382 buf[--charPos] = Integer.digits[((int) val) & mask]; |
378 val >>>= shift; |
383 val >>>= shift; |
379 } while (val != 0 && charPos > 0); |
384 } while (charPos > offset); |
380 |
|
381 return charPos; |
|
382 } |
385 } |
383 |
386 |
384 /** |
387 /** |
385 * Returns a {@code String} object representing the specified |
388 * Returns a {@code String} object representing the specified |
386 * {@code long}. The argument is converted to signed decimal |
389 * {@code long}. The argument is converted to signed decimal |