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 byteToMac(byte[] resBytes) {
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < resBytes.length; i++) {
        String hex = Integer.toHexString(resBytes[i] & 0xFF);
        if (hex.length() == 1) {
            hex = '0' + hex;
        }/*from www. j  av  a  2  s  .  c  o  m*/
        buffer.append(hex.toUpperCase());
    }
    return buffer.toString();
}

From source file:Main.java

public static String Bytes2HexString(byte[] b) {
    String ret = "";
    for (int i = 0; i < b.length; i++) {
        String hex = Integer.toHexString(b[i] & 0xFF);
        if (hex.length() == 1) {
            hex = "0" + hex;
        }//from www  .  j a va 2s. co m
        ret += hex.toUpperCase() + " ";
    }
    return ret;
}

From source file:Main.java

public static String ubytesToString16(byte[] data, int offset, int len) {
    StringBuilder sb = new StringBuilder();
    if (len > 0) {
        int p = offset;
        sb.append(Integer.toHexString(data[p++] & 0xFF));
        for (int i = 1; i < len; ++i) {
            sb.append(',').append(Integer.toHexString(data[p++] & 0xFF));
        }//from w  ww.  j  a va2  s . com
    }
    return sb.toString();
}

From source file:Main.java

public static String getColorHexString(int color) {
    String colorHex = "#";
    String a = Integer.toHexString(Color.alpha(color));
    if (a.length() == 1)
        a = "0" + a;
    String r = Integer.toHexString(Color.red(color));
    if (r.length() == 1)
        r = "0" + r;
    String g = Integer.toHexString(Color.green(color));
    if (g.length() == 1)
        g = "0" + g;
    String b = Integer.toHexString(Color.blue(color));
    if (b.length() == 1)
        b = "0" + b;
    colorHex += a + r + g + b;/* w ww .  j a v  a2 s. c  o m*/
    return colorHex;
}

From source file:Main.java

public static String toHexString(byte[] b) {
    StringBuffer buffer = new StringBuffer();
    if (b != null)
        for (int i = 0; i < b.length; ++i) {
            String s = Integer.toHexString(b[i] & 0xFF);
            if (s.length() == 1) {
                s = "0" + s;
            }/*from w w  w.  j  av  a 2s.  c  o m*/
            buffer.append(s + " ");
        }
    return buffer.toString();
}

From source file:Main.java

public static String hex(byte[] array) {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < array.length; ++i) {
        sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3));
    }/*from  www .ja va2  s  . c o  m*/
    return sb.toString();
}

From source file:Main.java

public static String byteToHexStr(byte[] b, int length) {
    String stmp = "";
    StringBuilder sb = new StringBuilder("");
    for (int n = 0; n < length; n++) {
        stmp = Integer.toHexString(b[n] & 0xFF);
        sb.append((stmp.length() == 1) ? "0" + stmp : stmp);
        //sb.append(" ");
    }//from  w  w w.  j ava2s  . c  om
    return sb.toString().toUpperCase().trim();
}

From source file:Main.java

public static String byte2HexStrSpace(byte[] b, int length) {
    String stmp = "";
    StringBuilder sb = new StringBuilder("");
    for (int n = 0; n < length; n++) {
        stmp = Integer.toHexString(b[n] & 0xFF);
        sb.append((stmp.length() == 1) ? "0" + stmp : stmp);
        sb.append(" ");
    }/*from   w w w  . ja va  2s  .c  om*/
    return sb.toString().toUpperCase().trim();
}

From source file:Main.java

public static String makeDeviceID(byte[] bytes) {
    if (bytes.length < 12)
        return "";
    StringBuffer sb = new StringBuffer();
    for (byte b : bytes) {
        sb.append(Integer.toHexString((b & 0xFF) | 0xFFFFFF00).substring(6).toUpperCase());
    }/*from  w  w w.  j  a va 2s.  co  m*/
    return sb.toString();
}

From source file:Main.java

public static String toHexString(byte[] input) {
    StringBuffer sb = new StringBuffer(input.length);
    String sTemp;//www  .  ja  v a 2  s  .co m
    for (int i = 0; i < input.length; i++) {
        sTemp = Integer.toHexString(0xFF & input[i]);
        if (sTemp.length() < 2)
            sb.append(0);
        sb.append(sTemp.toUpperCase());
    }
    return sb.toString();
}