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 Bytes2HexString(byte[] b, int size) {
    String ret = "";
    //for (int i = 0; i < size; i++) {
    for (int i = size - 1; i >= 0; i--) {
        String hex = Integer.toHexString(b[i] & 0xFF);
        if (hex.length() == 1) {
            hex = "0" + hex;
        }/*from  w ww  .j  a  v  a  2 s  .c  o m*/
        ret += hex.toUpperCase();
    }
    return ret;
}

From source file:Main.java

public static String byte2HexStrNonSpace(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 ava  2 s  .  c  o m*/
    return sb.toString().toUpperCase().trim();
}

From source file:Main.java

public static String getCnASCII(String str) {
    StringBuffer sb = new StringBuffer();
    byte[] strByte = str.getBytes();
    for (int i = 0; i < strByte.length; i++) {
        sb.append(Integer.toHexString(strByte[i] & 0xff));
    }/*from  w ww .  j  av a2 s. co  m*/
    return sb.toString();
}

From source file:Main.java

private static void dumpHex(String aTitle, byte[] anArray) {
    System.err.println();/*from  w  w w.j  a v a2 s.  com*/
    System.err.println(aTitle);
    for (int i = 0; i < anArray.length; i++) {
        System.err.print(Integer.toHexString(anArray[i]) + " ");
    }

    System.err.println();
}

From source file:Main.java

private static String bytesToHexString(byte[] bytes) {
    StringBuilder sb = new StringBuilder();
    for (byte aByte : bytes) {
        String hex = Integer.toHexString(255 & aByte);
        if (hex.length() == 1) {
            sb.append('0');
        }/*  w  w  w. j  a v  a  2 s .c o m*/
        sb.append(hex);
    }
    return sb.toString();
}

From source file:Main.java

public static String byte2hex(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/*from   ww  w  .j av  a2s  .  c o  m*/
            hs = hs + stmp;
        if (n < b.length - 1)
            hs = (new StringBuffer(String.valueOf(hs))).toString();
    }

    return hs.toUpperCase();
}

From source file:Main.java

public static String parseByte2HexStr(byte buf[]) {
    StringBuilder stringBuilder = new StringBuilder();
    for (byte b : buf) {
        String hex = Integer.toHexString(b & 0xFF);
        if (hex.length() == 1) {
            hex = '0' + hex;
        }//w ww .ja  va 2  s . co  m
        stringBuilder.append(hex.toUpperCase());
    }
    return stringBuilder.toString();
}

From source file:Main.java

@SuppressWarnings("unused")
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;
        }//www . j av  a  2s.  c o  m
        sb.append(hex.toUpperCase());
    }
    return sb.toString();
}

From source file:Main.java

public static String getCnASCII(String cnStr) {
    StringBuffer strBuf = new StringBuffer();
    byte[] bGBK = cnStr.getBytes();
    for (int i = 0; i < bGBK.length; i++) {
        strBuf.append(Integer.toHexString(bGBK[i] & 0xff));
    }//  w ww  .  ja v a2s .c  o  m
    return strBuf.toString();
}

From source file:Main.java

public static String byteToHexString(byte[] b) {
    StringBuffer hexString = new StringBuffer();
    for (byte b2 : b) {
        String hex = Integer.toHexString(b2 & MotionEventCompat.ACTION_MASK);
        if (hex.length() == 1) {
            hex = '0' + hex;
        }//from w w  w.j av  a2s.c o m
        hexString.append(hex.toLowerCase());
    }
    return hexString.toString();
}