Java Integer to Hex asHex(int val)

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

Description

Returns a hex string representation of the given int value.

License

Open Source License

Parameter

Parameter Description
val the value

Return

a string representing the value in hex

Declaration

public static String asHex(int val) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /** Hex string prefix. */
    private static final String OX = "0x";

    /**/*  ww w. ja  v a  2  s.  c  o  m*/
     * Returns a hex string representation of the given long value.
     *
     * @param val the value
     * @return a string representing the value in hex
     */
    public static String asHex(long val) {
        String h = Long.toHexString(val);
        return OX + h;
    }

    /**
     * Returns a hex string representation of the given int value.
     *
     * @param val the value
     * @return a string representing the value in hex
     */
    public static String asHex(int val) {
        String h = Integer.toHexString(val);
        return OX + h;
    }
}

Related

  1. asHex(final int value)
  2. asHex(int i)
  3. asHex(int i, int width)
  4. convertIntArrayToHexString(int[] arr)
  5. convertIntToHex(int i)
  6. convertInttoHexa(int n)
  7. int2CharHex(int integer)