Java Hex Calculate toHex(String val)

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

Description

to Hex

License

LGPL

Declaration

public static String toHex(String val) 

Method Source Code

//package com.java2s;

public class Main {
    public static String toHex(String val) {
        String ret = "0x";
        for (int i = 0; i < val.length(); i++) {
            ret += toHex(val.charAt(i), 2);
        }/*from   w w  w  . j av a 2 s. com*/
        return ret;
    }

    public static String toHex(char c, int width) {
        int i = (int) c;
        return toHex(i, width);
    }

    public static String toHex(int val, int width) {
        String s = Integer.toHexString(val).toUpperCase();
        while (s.length() < width) {
            s = "0" + s;
        }
        return s;
    }
}

Related

  1. toHEX(String ostr)
  2. toHex(String source)
  3. toHex(String str)
  4. toHex(String string)
  5. toHex(String txt)
  6. toHex(StringBuffer buf, long value, int width)
  7. toHex(StringBuilder s, byte b)
  8. toHex00String(int c)
  9. toHEX1(byte b)