Java Hex Calculate toHexString(String s)

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

Description

to Hex String

License

Open Source License

Declaration

public static String toHexString(String s) 

Method Source Code

//package com.java2s;

public class Main {
    public static final int UNI_SUR_HIGH_START = 0xD800;
    public static final int UNI_SUR_HIGH_END = 0xDBFF;
    public static final int UNI_SUR_LOW_START = 0xDC00;
    public static final int UNI_SUR_LOW_END = 0xDFFF;

    public static String toHexString(String s) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if (i > 0) {
                sb.append(' ');
            }/*www  . ja  va2  s.  c  om*/
            if (ch < 128) {
                sb.append(ch);
            } else {
                if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END) {
                    sb.append("H:");
                } else if (ch >= UNI_SUR_LOW_START && ch <= UNI_SUR_LOW_END) {
                    sb.append("L:");
                } else if (ch > UNI_SUR_LOW_END) {
                    if (ch == 0xffff) {
                        sb.append("F:");
                    } else {
                        sb.append("E:");
                    }
                }

                sb.append("0x" + Integer.toHexString(ch));
            }
        }
        return sb.toString();
    }
}

Related

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