Java Integer to Hex int2HexString(StringBuilder buf, int value)

Here you can find the source of int2HexString(StringBuilder buf, int value)

Description

This method avoids the use on Integer.toHexString, since this class may be used during the boot-phase when the Integer class in not yet initialized.

License

Open Source License

Parameter

Parameter Description
buf a parameter
value a parameter

Declaration

private static void int2HexString(StringBuilder buf, int value) 

Method Source Code

//package com.java2s;
/*/* ww w.j  a v  a2  s .c om*/
 * $Id$
 *
 * Copyright (C) 2003-2015 JNode.org
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This library 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 Lesser General Public 
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; If not, write to the Free Software Foundation, Inc., 
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

public class Main {
    /**
     * This method avoids the use on Integer.toHexString, since this class may be used
     * during the boot-phase when the Integer class in not yet initialized.
     *
     * @param buf
     * @param value
     */
    private static void int2HexString(StringBuilder buf, int value) {
        int rem = value & 0x0F;
        int q = value >>> 4;
        if (q != 0) {
            int2HexString(buf, q);
        }

        if (rem < 10) {
            buf.append((char) ('0' + rem));
        } else {
            buf.append((char) ('A' + rem - 10));
        }
    }
}

Related

  1. int2HexChar(int val)
  2. int2HexChars(final int data)
  3. int2HexString(final int i)
  4. int2HexString(int n)
  5. int2hexString(int x)
  6. int2HexZeroPad(int i)
  7. integerToHex(final Object value, final int desimals)
  8. integerToHex(final Object value, final int desimals)
  9. integerToHex(int val)