Example usage for java.lang Integer toHexString

List of usage examples for java.lang Integer toHexString

Introduction

In this page you can find the example usage for java.lang Integer toHexString.

Prototype

public static String toHexString(int i) 

Source Link

Document

Returns a string representation of the integer argument as an unsigned integer in base 16.

Usage

From source file:Main.java

public static String byte2hexNoUpperCase(byte[] bytes) {
    StringBuilder sign = new StringBuilder();
    for (int i = 0; i < bytes.length; i++) {
        String hex = Integer.toHexString(bytes[i] & 0xFF);
        if (hex.length() == 1) {
            sign.append("0");
        }//from  w  ww. j  av a 2s .  c  o  m
        sign.append(hex);
    }
    return sign.toString();
}

From source file:Main.java

public static String byte2hex(byte[] b) {
    StringBuffer sb = new StringBuffer();
    String stmp = "";
    for (int n = 0; n < b.length; n++) {
        stmp = Integer.toHexString(b[n] & 0XFF);
        if (stmp.length() == 1) {
            sb.append("0" + stmp);
        } else {/* w w w .j  av  a 2  s  .co m*/
            sb.append(stmp);
        }
    }
    return sb.toString();
}

From source file:Main.java

public static String printHexString(byte[] b) {
    String a = "";
    for (int i = 0; i < b.length; i++) {
        String hex = Integer.toHexString(b[i] & 0xFF);
        if (hex.length() == 1) {
            hex = '0' + hex;
        }//from w w  w  .  j a  v a2 s  .co m

        a = a + hex;
    }
    return a;
}

From source file:Main.java

public static String hexify(int inInteger, boolean inCase) {
    return Integer.toHexString(inInteger);
}

From source file:Main.java

private static String byteToHexString(byte[] digest) {
    StringBuffer hexString = new StringBuffer();
    for (int i = 0; i < digest.length; i++) {
        String hex = Integer.toHexString(digest[i] & 0xFF);
        if (hex.length() == 1) {
            hex = '0' + hex;
        }// w  w w  .j a v a2 s  .  co m
        hexString.append(hex.toUpperCase());
    }
    return hexString.toString();
}

From source file:Main.java

public static String byte2HexStr(byte[] b) {
    String stmp = "";
    StringBuilder sb = new StringBuilder("");
    for (int n = 0; n < b.length; n++) {
        stmp = Integer.toHexString(b[n] & 0xFF);
        sb.append((stmp.length() == 1) ? "0" + stmp : stmp);
        sb.append("");
    }/*  w  w w.  jav  a 2 s  . com*/
    return sb.toString().toUpperCase().trim();
}

From source file:Main.java

private static String hex(byte b) {
    return "0x" + Integer.toHexString((int) (b & 0xff)) + " ";
}

From source file:Main.java

public static String printByteArrayAsInt(String caller, byte[] data) {
    String ret = "";
    for (int i = 0; i < data.length; i++) {
        ret += Integer.toHexString((int) (data[i] & 0xFF)) + ",";
        Log.i(caller, "Byte " + i + " is " + Integer.toHexString((int) (data[i] & 0xFF)));
    }// w  w w .j  a va  2s.co m
    return ret;
}

From source file:Main.java

public static String byte2hex(byte[] b) {
    StringBuffer sb = new StringBuffer(b.length * 2);
    String tmp = "";
    for (int n = 0; n < b.length; n++) {
        tmp = (Integer.toHexString(b[n] & 0XFF));
        if (tmp.length() == 1) {
            sb.append("0");
        }//from  w  w  w .j av a2s .  c  o  m
        sb.append(tmp);
    }
    return sb.toString().toUpperCase();
}

From source file:Main.java

public static String toHex(byte[] bytes) {
    StringBuffer buf = new StringBuffer("");
    String tmp = null;//  ww  w.j av a2s  . com

    for (int i = 0; i < bytes.length; i++) {
        tmp = (Integer.toHexString(bytes[i] & 0xFF));
        if (tmp.length() == 1) {
            buf.append("0");
        }
        buf.append(tmp);
    }
    return buf.toString();
}