Here you can find the source of fromHex(String s)
public static byte fromHex(String s)
//package com.java2s; //License from project: Apache License public class Main { private static final String HEX_STRING = "0123456789abcdef"; public static byte fromHex(String s) { if (s.length() != 2) { throw new IllegalArgumentException("Invalid length of string."); }/* w w w .j av a 2s.co m*/ char c1 = s.charAt(0); char c2 = s.charAt(1); int n1 = HEX_STRING.indexOf(c1); int n2 = HEX_STRING.indexOf(c2); if (n1 == (-1)) { throw new IllegalArgumentException("Invalid char in string: " + c1); } if (n2 == (-1)) { throw new IllegalArgumentException("Invalid char in string: " + c2); } int n = (n1 << 4) + n2; return (byte) n; } }