Example usage for java.lang Integer toString

List of usage examples for java.lang Integer toString

Introduction

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

Prototype

public static String toString(int i, int radix) 

Source Link

Document

Returns a string representation of the first argument in the radix specified by the second argument.

Usage

From source file:Main.java

public static String getHexString(byte[] b) throws Exception {
    String result = "";
    for (int i = 0; i < b.length; i++) {
        result += Integer.toString((b[i] & 0xFF) + 0x100, 16).substring(1);
    }// ww  w.jav a 2s. com
    return result;
}

From source file:Main.java

public static String getHexString(byte[] b) {
    String result = "";
    for (int i = 0; i < b.length; i++) {
        result += Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1);
    }/*from   ww  w. jav  a 2 s.c  o m*/
    return result;
}

From source file:Main.java

public static String md5ToString(byte[] md5in) {
    String signature2 = "";

    for (int i = 0; i < md5in.length; i++) {
        signature2 += Integer.toString((md5in[i] & 0xff) + 0x100, 16).substring(1);
    }// w w  w  . jav  a  2 s .co m
    return signature2;
}

From source file:Main.java

private static String byte2hexString(byte buf[]) {
    StringBuffer strbuf = new StringBuffer(buf.length * 2);
    int i;//from w ww.  j av a  2s. c o  m
    for (i = 0; i < buf.length; i++) {
        strbuf.append(Integer.toString((buf[i] >> 4) & 0xf, 16) + Integer.toString(buf[i] & 0xf, 16));
    }

    return strbuf.toString();
}

From source file:Main.java

public static String ConvertHexByteToString(byte byteToConvert) {
    String ConvertedByte = "";
    if (byteToConvert < 0) {
        ConvertedByte += Integer.toString(byteToConvert + 256, 16) + " ";
    } else if (byteToConvert <= 15) {
        ConvertedByte += "0" + Integer.toString(byteToConvert, 16) + " ";
    } else {/*  w  w  w  .  j  a v  a2s.c  om*/
        ConvertedByte += Integer.toString(byteToConvert, 16) + " ";
    }

    return ConvertedByte;
}

From source file:Util.java

public static String dumpHex(byte[] bytes) {
    StringBuffer buf = new StringBuffer();
    int aByte;/*from   w  w w  . ja  v  a  2 s . c om*/
    for (int i = 0; i < bytes.length; i++) {
        aByte = bytes[i];
        if (aByte < 0)
            aByte += 0x100;
        buf.append("[" + Integer.toString(aByte, 16) + "]");
    }
    return buf.toString();
}

From source file:Main.java

public static String encodeHex(byte[] bytes) {
    StringBuilder hex = new StringBuilder(bytes.length * 2);

    for (byte aByte : bytes) {
        if (((int) aByte & 0xff) < 0x10) {
            hex.append("0");
        }//from ww  w  .  j  a v a  2s.c o m
        hex.append(Integer.toString((int) aByte & 0xff, 16));
    }

    return hex.toString();
}

From source file:Main.java

/**
 * Generate a random message-id header for locally-generated messages.
 *//*from   w ww . jav  a 2 s .co m*/
public static String generateMessageId() {
    StringBuffer sb = new StringBuffer();
    sb.append("<");
    for (int i = 0; i < 24; i++) {
        sb.append(Integer.toString((int) (Math.random() * 35), 36));
    }
    sb.append(".");
    sb.append(Long.toString(System.currentTimeMillis()));
    sb.append("@email.android.com>");
    return sb.toString();
}

From source file:Main.java

public static String calculateMd5Checksum(String filename) {
    String result = "";
    try {//  w  w  w.j a va  2  s .  c  o m
        byte[] b = createChecksumBytes(filename, "MD5");
        // convert bytes to HEX strings
        for (int i = 0; i < b.length; i++) {
            result += Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1);
        }
    } catch (Exception ex) {
        throw new RuntimeException("Error: " + ex.toString(), ex);
    }
    return result;
}

From source file:Main.java

/**
 * Transforms a byte array in a hex string
 * /*w  w  w  .  ja  v a  2  s.  c  o  m*/
 * @param digest
 *            Digest
 * @return Display ready string
 */
public static String ToHexString(byte[] digest) {
    StringBuffer hexStr = new StringBuffer(40);
    for (byte b : digest) {
        hexStr.append(Integer.toString((b & 0xff) + 0x100, 16).substring(1));
    }
    return hexStr.toString();
}