Java Hex Calculate toHex(int val)

Here you can find the source of toHex(int val)

Description

Converts one int to a hexadecimal ASCII string.

License

Open Source License

Parameter

Parameter Description
val The integer

Return

The hex string

Declaration

public static String toHex(int val) 

Method Source Code

//package com.java2s;

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

    /**/*from  www  .  j  av a2 s.co m*/
     * Converts one int to a hexadecimal ASCII string.
     *
     * @param val The integer
     * @return The hex string
     */
    public static String toHex(int val) {
        int val1, val2;

        val1 = (val >> 4) & 0x0F;
        val2 = (val & 0x0F);

        return ("" + HEX_DIGIT[val1] + HEX_DIGIT[val2]);
    }
}

Related

  1. toHex(int nybble)
  2. toHex(int r, int g, int b)
  3. toHex(int r, int g, int b)
  4. toHex(int r, int g, int b)
  5. toHex(int v)
  6. toHex(int val)
  7. toHex(int value)
  8. toHEX(int value)
  9. toHex(int value)