Java Hex Calculate toHexString(String s)

Here you can find the source of toHexString(String s)

Description

to Hex String

License

Apache License

Declaration

public static String toHexString(String s) 

Method Source Code

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

public class Main {
    public static String toHexString(String s) {
        byte[] baKeyword = new byte[s.length() / 2];
        for (int i = 0; i < baKeyword.length; i++) {
            try {
                baKeyword[i] = (byte) (0xff & Integer.parseInt(s.substring(i * 2, i * 2 + 2), 16));
            } catch (Exception e) {
                e.printStackTrace();//from   w  ww  .j  av  a2s  .c o  m
            }
        }

        try {
            s = new String(baKeyword, "utf-8");// UTF-16le:Not
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        return s;
    }
}

Related

  1. ToHexString(long[] data)
  2. toHexString(String data)
  3. toHexString(String input)
  4. toHexString(String s)
  5. toHexString(String s)
  6. toHexString(String str)
  7. toHexString(String str)
  8. toHexString(StringBuffer buffer, byte[] bytes, int numBytes)
  9. toHexString0x(byte[] byteArray)