Java Integer to Hex intToHexString(int value)

Here you can find the source of intToHexString(int value)

Description

Convert an integer value into a hexadecimal representation that is long enough to contain the significant digits.

License

Open Source License

Parameter

Parameter Description
value The integer value to be converted

Return

The string representation of the value as a hexadecimal representation

Declaration

public static String intToHexString(int value) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from  w  ww. ja  v a  2s.  c  om
     * A static array of the hexadecimal digits where their position represents their ordinal value
     */
    private static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
            'E', 'F' };

    /**
     * Convert an integer value into a hexadecimal representation that is long enough to contain the significant digits.
     * 
     * @param value
     *            The integer value to be converted
     * @return The string representation of the value as a hexadecimal representation
     */
    public static String intToHexString(int value) {
        StringBuffer buffer = new StringBuffer();
        int temp = value;
        do {
            int index = temp % 16;
            buffer.insert(0, HEX_DIGITS[index]);
            temp = temp / 16;
        } while (temp > 0);
        return buffer.toString();
    }
}

Related

  1. intToHexString(int i)
  2. intToHexString(int i)
  3. intToHexString(int num)
  4. intToHexString(int number)
  5. intToHexString(int val, int width)
  6. intToHexString(int value, int digits)
  7. intToHexWithPadding(Integer input, Integer max_size)