Android Hex String Create toHex(String txt)

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

Description

to Hex

Declaration

public static String toHex(String txt) 

Method Source Code

//package com.java2s;

public class Main {
    private final static String HEX = "0123456789ABCDEFG";

    public static String toHex(String txt) {
        return toHex(txt.getBytes());
    }/*  www.ja  v  a2s  .c  om*/

    private static String toHex(byte[] buf) {
        if (buf == null)
            return "";
        StringBuffer result = new StringBuffer(2 * buf.length);
        for (int i = 0; i < buf.length; i++) {
            appendHex(result, buf[i]);
        }
        return result.toString();
    }

    private static void appendHex(StringBuffer sb, byte b) {
        sb.append(HEX.charAt((b >> 4) & 0x0f)).append(HEX.charAt(b & 0x0f));
    }
}

Related

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