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 characters' unicode in hexadecimal.
 *//*  w  w w . j  a va 2  s.  c  o  m*/
public static String getUnicode(String text, int len_limit) {
    if (TextUtils.isEmpty(text) || len_limit <= 0) {
        return "";
    }

    StringBuilder stringBuilder = new StringBuilder();

    final char[] CHARS = text.toCharArray();
    for (int len = CHARS.length, i = len - 1; i >= 0; --i) {
        if (len - i <= len_limit) {
            stringBuilder.insert(0, Integer.toHexString(CHARS[i]).toUpperCase());
            stringBuilder.insert(0, " ");
        } else {
            stringBuilder.insert(0, " ...");
            break;
        }
    }

    //Remove the first superfluous " ".
    return stringBuilder.substring(1);
}

From source file:Main.java

public static final String md5(String tps) {
    final String MD5 = "MD5";
    try {/*from w  w w.j a  va  2s .c  o  m*/
        // Create MD5 Hash
        MessageDigest digest = MessageDigest.getInstance(MD5);
        digest.update(tps.getBytes());
        byte messageDigest[] = digest.digest();

        // Create Hex String
        StringBuilder hexString = new StringBuilder();
        for (byte aMessageDigest : messageDigest) {
            String h = Integer.toHexString(0xFF & aMessageDigest);
            while (h.length() < 2)
                h = "0" + h;
            hexString.append(h);
        }
        return hexString.toString();

    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:Main.java

public static final String encryptMd5String(String s) {
    try {//from w  w w .j av a2s. c  o  m
        byte[] btInput = s.getBytes();
        MessageDigest mdInst = MessageDigest.getInstance("MD5");
        mdInst.update(btInput);
        byte[] md = mdInst.digest();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < md.length; i++) {
            int val = ((int) md[i]) & 0xff;
            if (val < 16) {
                sb.append("0");
            }
            sb.append(Integer.toHexString(val));
        }
        return sb.toString();
    } catch (Exception e) {
        return null;
    }
}

From source file:Main.java

static public String md5(String string) {
    try {/*  w  w w. ja v  a  2 s . com*/
        // Create MD5 Hash
        java.security.MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
        digest.update(string.getBytes());
        byte messageDigest[] = digest.digest();

        // Create Hex String
        StringBuilder hexString = new StringBuilder();
        for (byte aMessageDigest : messageDigest) {
            String h = Integer.toHexString(0xFF & aMessageDigest);
            while (h.length() < 2)
                h = "0" + h;
            hexString.append(h);
        }
        return hexString.toString();

    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:Main.java

public static String md5(String s) {

    sMd5MessageDigest.reset();//from  w w w  .  j a v  a 2s  .c  o  m
    sMd5MessageDigest.update(s.getBytes());

    byte digest[] = sMd5MessageDigest.digest();

    sStringBuilder.setLength(0);
    for (int i = 0; i < digest.length; i++) {
        final int b = digest[i] & 255;
        if (b < 16) {
            sStringBuilder.append('0');
        }
        sStringBuilder.append(Integer.toHexString(b));
    }

    return sStringBuilder.toString();
}

From source file:Main.java

public static void buildShortClassTag(Object cls, StringBuilder out) {
    if (cls == null) {
        out.append("null");
        return;//  www.  j  a  v  a2 s .c  o m
    }
    String simpleName = cls.getClass().getSimpleName();
    if (simpleName == null || simpleName.length() <= 0) {
        simpleName = cls.getClass().getName();
        int end = simpleName.lastIndexOf(46);
        if (end > 0) {
            simpleName = simpleName.substring(end + 1);
        }
    }
    out.append(simpleName);
    out.append('{');
    out.append(Integer.toHexString(System.identityHashCode(cls)));
}

From source file:Main.java

private static String encodeChar(char c) {
    StringBuilder buf = new StringBuilder();
    buf.append("_x");
    String str = Integer.toHexString(c);
    for (int i = 4 - str.length(); i > 0; i--) {
        buf.append("0");
    }//from  w w  w  .j ava 2 s.c om
    return buf.append(str).append("_").toString();
}

From source file:Main.java

private static String md5(String input) {
    final String MD5 = "MD5";
    try {//w w  w  .  j  a  va  2s.  c o m
        // Create MD5 Hash
        MessageDigest digest = java.security.MessageDigest.getInstance(MD5);
        digest.update(input.getBytes());
        byte messageDigest[] = digest.digest();

        // Create Hex String
        StringBuilder hexString = new StringBuilder();
        for (byte aMessageDigest : messageDigest) {
            String h = Integer.toHexString(0xFF & aMessageDigest);
            while (h.length() < 2)
                h = "0" + h;
            hexString.append(h);
        }
        return hexString.toString();

    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

private static final String md5(final String s) {
    final String MD5 = "MD5";
    try {//from  w  w w . j ava2s .  c  o  m
        // Create MD5 Hash
        MessageDigest digest = java.security.MessageDigest.getInstance(MD5);
        digest.update(s.getBytes());
        byte messageDigest[] = digest.digest();

        // Create Hex String
        StringBuilder hexString = new StringBuilder();
        for (byte aMessageDigest : messageDigest) {
            String h = Integer.toHexString(0xFF & aMessageDigest);
            while (h.length() < 2)
                h = "0" + h;
            hexString.append(h);
        }
        return hexString.toString();

    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:Main.java

public static String getARGBString(int value) {
    return "#" + Integer.toHexString(value);
}