Java Integer to String intToString(int n)

Here you can find the source of intToString(int n)

Description

Returns a string of 8 hexadecimal digits (most significant digit first) corresponding to the integer n, which is treated as unsigned.

License

Open Source License

Declaration

public static String intToString(int n) 

Method Source Code

//package com.java2s;
/*/*from  w w w.  j  a va 2  s  .  co  m*/
 * Copyright (c) 1995-2008 Uwe B. Meding <uwe@uwemeding.com>
 *
 * This file is part of DTDC
 * This PCA software is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * DTDC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with DTDC.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    private static final char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
            'E', 'F' };

    /**
     * Returns a string of 8 hexadecimal digits (most significant digit first)
     * corresponding to the integer n, which is treated as unsigned.
     */
    public static String intToString(int n) {
        char[] buf = new char[8];

        for (int i = 7; i >= 0; i--) {
            buf[i] = hexDigits[n & 0x0F];
            n >>>= 4;
        }
        return new String(buf);
    }
}

Related

  1. intToString(final long v, final int length)
  2. intToString(int i)
  3. intToString(int i)
  4. intToString(int i)
  5. intToString(int integer)
  6. intToString(int theValue, int nDigits)
  7. intToString(int val, int width)
  8. intToString(int value)
  9. IntToString(int value)