Android String to Hex String Convert str2HexStr(String str)

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

Description

str Hex Str

Declaration

public static String str2HexStr(String str) 

Method Source Code

//package com.java2s;

public class Main {

    public static String str2HexStr(String str) {
        char[] chars = "0123456789ABCDEF".toCharArray();
        StringBuilder sb = new StringBuilder("");
        byte[] bs = str.getBytes();
        int bit;//from   www  .j a  v a2  s  .com
        for (int i = 0; i < bs.length; i++) {
            bit = (bs[i] & 0x0f0) >> 4;
            sb.append("0x");
            sb.append(chars[bit]);
            bit = bs[i] & 0x0f;
            sb.append(chars[bit]);
            sb.append(", ");
        }
        return sb.toString();
    }
}

Related

  1. hexStringToCommonString(String hexString)
  2. toHex(String txt)
  3. toHex(String txt)
  4. parseHexStr2Byte(String hexStr)
  5. stringToHex(String string)
  6. str2HexStrExt(String str)