jdk/src/share/classes/java/lang/Integer.java
changeset 25660 01fa3ccedf50
parent 25653 41e5fa7ce490
equal deleted inserted replaced
25659:14764f69ed82 25660:01fa3ccedf50
   318         // Use special constructor which takes over "buf".
   318         // Use special constructor which takes over "buf".
   319         return new String(buf, true);
   319         return new String(buf, true);
   320     }
   320     }
   321 
   321 
   322     /**
   322     /**
   323      * Format a long (treated as unsigned) into a character buffer.
   323      * Format an {@code int} (treated as unsigned) into a character buffer. If
       
   324      * {@code len} exceeds the formatted ASCII representation of {@code val},
       
   325      * {@code buf} will be padded with leading zeroes.
       
   326      *
   324      * @param val the unsigned int to format
   327      * @param val the unsigned int to format
   325      * @param shift the log2 of the base to format in (4 for hex, 3 for octal, 1 for binary)
   328      * @param shift the log2 of the base to format in (4 for hex, 3 for octal, 1 for binary)
   326      * @param buf the character buffer to write to
   329      * @param buf the character buffer to write to
   327      * @param offset the offset in the destination buffer to start at
   330      * @param offset the offset in the destination buffer to start at
   328      * @param len the number of characters to write
   331      * @param len the number of characters to write
   329      * @return the lowest character  location used
   332      */
   330      */
   333      static void formatUnsignedInt(int val, int shift, char[] buf, int offset, int len) {
   331      static int formatUnsignedInt(int val, int shift, char[] buf, int offset, int len) {
   334         // assert shift > 0 && shift <=5 : "Illegal shift value";
   332         int charPos = len;
   335         // assert offset >= 0 && offset < buf.length : "illegal offset";
       
   336         // assert len > 0 && (offset + len) <= buf.length : "illegal length";
       
   337         int charPos = offset + len;
   333         int radix = 1 << shift;
   338         int radix = 1 << shift;
   334         int mask = radix - 1;
   339         int mask = radix - 1;
   335         do {
   340         do {
   336             buf[offset + --charPos] = Integer.digits[val & mask];
   341             buf[--charPos] = Integer.digits[val & mask];
   337             val >>>= shift;
   342             val >>>= shift;
   338         } while (val != 0 && charPos > 0);
   343         } while (charPos > offset);
   339 
       
   340         return charPos;
       
   341     }
   344     }
   342 
   345 
   343     final static char [] DigitTens = {
   346     final static char [] DigitTens = {
   344         '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
   347         '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
   345         '1', '1', '1', '1', '1', '1', '1', '1', '1', '1',
   348         '1', '1', '1', '1', '1', '1', '1', '1', '1', '1',