Android Hex String Create toHex(String str)

Here you can find the source of toHex(String str)

Description

to Hex

License

Apache License

Declaration

public static String toHex(String str) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {

    public static String toHex(String str) {
        String hexString = "0123456789ABCDEF";
        byte[] bytes = str.getBytes();
        StringBuilder sb = new StringBuilder(bytes.length * 2);
        for (byte aByte : bytes) {
            char temp1 = hexString.charAt((aByte & 0xf0) >> 4);
            char temp2 = hexString.charAt(aByte & 0x0f);
            if (!(temp1 == '0' && temp2 == '0')) {
                sb.append(temp1);//from   w  w w.j  a  v a 2 s  . c o m
                sb.append(temp2);
            }
        }
        return sb.toString();
    }
}

Related

  1. hex(int value, int digits)
  2. hexCharToInt(char c)
  3. hexDecode(String str, byte[] ba, int len)
  4. hexEncode(byte[] aInput)
  5. hexify(byte bytes[])
  6. toHex(String txt)
  7. toHex(byte b)
  8. toHex(byte input[])
  9. toHex(byte[] bytes)