Java Integer to Hex asHex(int i)

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

Description

as Hex

License

Open Source License

Declaration

public static String asHex(int i) 

Method Source Code

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

public class Main {
    private static final String zeroChars = "00000000";

    public static String asHex(int i, boolean hexIsDefault, boolean signed, boolean padZero) {
        String sign = "";
        if (signed && i < 0) {
            sign = "-";
            i = -i;/*from w w  w  .j  a va2 s.  com*/
        }
        String s = Integer.toHexString(i);
        return sign + (hexIsDefault ? (padZero ? zeroChars.substring(s.length()) : "") : (i < 10 ? "" : "0x")) + s;
    }

    public static String asHex(int i, boolean hexIsDefault) {
        return asHex(i, hexIsDefault, false, true);
    }

    public static String asHex(int i) {
        return asHex(i, true, false, true);
    }
}

Related

  1. asHex(final int value)
  2. asHex(int i, int width)
  3. asHex(int val)
  4. convertIntArrayToHexString(int[] arr)
  5. convertIntToHex(int i)