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

/**
 * Get the mac address String format by the device's bssid bytes format
 * @param bssidBytes the device's bssid bytes format
 * @return the mac address String format
 *//*  w w w.jav a2s .  c  o m*/
public static String getMacAddressStr(byte[] bssidBytes) {
    StringBuilder sb = new StringBuilder();
    String segmentStr = null;
    for (int i = 0; i < bssidBytes.length; ++i) {
        segmentStr = Integer.toHexString(0xff & bssidBytes[i]);
        if (segmentStr.length() == 1) {
            sb.append("0");
        }
        sb.append(segmentStr);
        if (i != bssidBytes.length - 1) {
            sb.append(':');
        }
    }
    return sb.toString().toLowerCase(Locale.US);
}

From source file:Main.java

private static String bytesToHexString(byte[] src) {
    StringBuilder builder = new StringBuilder();
    if (src == null || src.length <= 0) {
        return null;
    }/*from  w  ww .  ja  v  a2 s. c  om*/
    String hv;
    for (int i = 0; i < src.length; i++) {
        hv = Integer.toHexString(src[i] & 0xFF).toUpperCase();
        if (hv.length() < 2) {
            builder.append(0);
        }
        builder.append(hv);
    }
    return builder.toString();
}

From source file:Main.java

static String toHexString(byte[] array) {
    if (array == null)
        return null;
    String s = "";
    for (byte b : array) {
        if ((Integer.toHexString(b).length() < 2))
            s += "0" + Integer.toHexString(b) + " ";
        else if ((Integer.toHexString(b).length() == 2))
            s += Integer.toHexString(b) + " ";
        else {/*  ww  w  .  j  av a2s. co m*/
            String temp = Integer.toHexString(b);
            temp = temp.substring(temp.length() - 2);
            s += temp + " ";
        }
    }
    return s;
}

From source file:Main.java

private static String getLockInfo(ReentrantLock lock) {
    String lockid = "Lock@" + Integer.toHexString(lock.hashCode());
    return "lock " + lockid + " held=" + lock.getHoldCount() + " isHeldMe=" + lock.isHeldByCurrentThread()
            + " hasQueueThreads=" + lock.hasQueuedThreads();
}

From source file:Main.java

private static String bytesToHexString(byte[] bArray) {
    if (bArray == null) {
        return null;
    }//from w ww  .j  a  v  a  2 s . co  m
    if (bArray.length == 0) {
        return "";
    }
    StringBuffer sb = new StringBuffer(bArray.length);
    String sTemp;
    for (int i = 0; i < bArray.length; 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

/**
 * use md5 algorithm/*ww  w  . j ava2  s.c o m*/
 * @param string the String need to encrypt
 * @return the encrypted result
 */
public static String md5(final String string) {
    byte[] hash;
    try {
        hash = MessageDigest.getInstance("MD5").digest(string.getBytes("UTF-8"));
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException("MD5 should be supported?", e);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException("UTF-8 should be supported?", e);
    }

    StringBuilder hex = new StringBuilder(hash.length * 2);
    for (byte b : hash) {
        if ((b & 0xFF) < 0x10)
            hex.append("0");
        hex.append(Integer.toHexString(b & 0xFF));
    }
    return hex.toString();
}

From source file:com.tag.HexUtils.java

public static String toHex(int i) {
    String hex = Integer.toHexString(i);
    int size = 2;
    hex = StringUtils.leftPad(hex, size, '0');
    hex = hex.toUpperCase();/*from   w  ww.j a  v a2s  .  c o  m*/
    int length = hex.length();
    int beginIndex = length - size;
    return hex.substring(beginIndex);
}

From source file:Main.java

private static String byte2HexStr(byte[] b) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < b.length; ++i) {
        String s = Integer.toHexString(b[i] & 0xFF);
        if (s.length() == 1)
            sb.append("0");

        sb.append(s.toUpperCase());/*from ww  w  . j  a  va2  s .c  o  m*/
    }
    return sb.toString();
}

From source file:Main.java

public static void checkGLError(String msg) {
    int error = GLES20.glGetError();
    if (error != GLES20.GL_NO_ERROR) {
        String str = msg + ": glError 0x" + Integer.toHexString(error);
        Log.e(TAG, str);/* w  ww .  j  a  v  a 2  s  .c o  m*/
        int values[] = new int[2];
        GLES20.glGetIntegerv(GLES20.GL_ARRAY_BUFFER_BINDING, values, 0);
        GLES20.glGetIntegerv(GLES20.GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, values, 1);
        Log.e(TAG, "Current bound array buffer: " + values[0]);
        Log.e(TAG, "Current bound vertex attrib: " + values[1]);
        throw new RuntimeException(msg);
    }
}

From source file:Main.java

public static String getCheckNum(String ggaString) {
    if (!ggaString.contains("$") || !ggaString.contains("*"))
        return null;
    String test = ggaString.substring(ggaString.indexOf("$") + 1, ggaString.indexOf("*"));
    char result = test.charAt(0);
    for (int i = 1; i < test.length(); i++)
        result ^= test.charAt(i);/*ww w .j  ava 2 s . c o m*/
    String bufferString = Integer.toHexString(result);
    if (bufferString.length() == 1)
        bufferString = "0".concat(bufferString);
    return bufferString;
}