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 void printHexString(String hint, byte[] b) {
    System.out.print(hint);//from  ww w. j  a  va  2 s .  c  o m
    for (int i = 0; i < b.length; i++) {
        String hex = Integer.toHexString(b[i] & 0xFF);
        if (hex.length() == 1) {
            hex = "0" + hex;
        }
        System.out.print(hex.toUpperCase() + " ");
    }
    System.out.println("");
}

From source file:Main.java

public static String getBCC(byte[] paramArrayOfByte) {
    byte[] arrayOfByte = new byte[1];
    for (int i = 0;; i++) {
        if (i >= paramArrayOfByte.length) {
            String str = Integer.toHexString(0xFF & arrayOfByte[0]);
            if (str.length() == 1) {
                str = '0' + str;
            }/*from  w w  w. j a v a2s  .c o  m*/
            return "" + str.toUpperCase();
        }
        arrayOfByte[0] = ((byte) (arrayOfByte[0] ^ paramArrayOfByte[i]));
    }
}

From source file:Main.java

public static String bytesToHexString(byte[] bArray, int count) {
    StringBuffer sb = new StringBuffer(bArray.length);

    String sTemp;/*from   www  . j  a  va  2s  .  c om*/
    for (int i = 0; i < count; i++) {
        sTemp = Integer.toHexString(0xFF & bArray[i]);
        if (sTemp.length() < 2)
            sb.append(0);
        sb.append(sTemp.toUpperCase());
    }
    return sb.toString();
}

From source file:Main.java

private static String parseByte2HexStr(byte buf[]) {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < buf.length; i++) {
        String hex = Integer.toHexString(buf[i] & 0xFF);
        if (hex.length() == 1) {
            hex = '0' + hex;
        }//from  ww w  . j a  va2s .  c o m
        sb.append(hex.toUpperCase());
    }
    return sb.toString();
}

From source file:Main.java

public static String byteArrayToHex(byte[] b) {
    String hs = "";
    String stmp = "";
    for (int n = 0; n < b.length; n++) {
        stmp = (Integer.toHexString(b[n] & 0XFF));
        if (stmp.length() == 1) {
            hs = hs + "0" + stmp;
        } else {//  www.j  a v  a2 s  .  c o m
            hs = hs + stmp;
        }
        if (n < b.length - 1) {
            hs = hs + "";
        }
    }
    // return hs.toUpperCase();
    return hs;
}

From source file:Main.java

public static final String bytesToHexString(byte[] bArray) {
    StringBuffer sb = new StringBuffer(bArray.length);
    String sTemp;/*from   w w w  .  j  a v a 2s  . c  o  m*/
    for (int i = 0; i < bArray.length; i++) {
        sTemp = Integer.toHexString((int) (0xFF & bArray[i]));
        if (sTemp.length() < 2)
            sb.append(0);
        sb.append(sTemp.toUpperCase());
        sb.append(" ");
    }
    return sb.toString();
}

From source file:Main.java

public static String byteArrayToHexString(byte[] b, int start, int stop) {
    String stmp = "";
    StringBuilder sb = new StringBuilder("");
    for (int n = start; n <= stop; n++) {
        stmp = Integer.toHexString(b[n] & 0xFF);
        sb.append((stmp.length() == 1) ? "0" + stmp : stmp);
        //sb.append(" ");
    }/*from  w ww .j  av  a 2 s  . com*/
    System.out.println("deviceinfo :" + sb);
    return sb.toString().toUpperCase().trim();
}

From source file:Main.java

public static String getColorAsHex(Context context, int colorId) {
    int color = getColorAsInt(context, colorId);

    return "#" + Integer.toHexString(color);
}

From source file:Main.java

private static String parseByte2HexStr(byte[] buf) {

    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < buf.length; i++) {
        String hex = Integer.toHexString(buf[i] & 0XFF);
        if (hex.length() == 1) {
            //            hex = '0' + hex;
            sb.append("0");
        }//  w  ww. j a v a  2  s . c o  m
        sb.append(hex);
    }
    return sb.toString().toUpperCase();
}

From source file:Main.java

public static String getHexString2(final byte[] b) {
    StringBuilder result = new StringBuilder();
    for (byte element : b) {
        int asInt = unsignedByteToInt(element);
        result.append(Integer.toHexString(asInt));
    }/*from   www .j a v a 2 s . co  m*/
    return result.toString();
}