1 7 package com.inversoft.savant; 8 9 10 17 public class StringTools { 18 19 28 public static byte [] fromHex(String hexString) { 29 int length = hexString.length(); 30 31 if ((length & 0x01) != 0) { 32 throw new IllegalArgumentException ("odd number of characters."); 33 } 34 35 byte[] out = new byte[length >> 1]; 36 37 for (int i = 0, j = 0; j < length; i++) { 39 int f = Character.digit(hexString.charAt(j++), 16) << 4; 40 f = f | Character.digit(hexString.charAt(j++), 16); 41 out[i] = (byte) (f & 0xFF); 42 } 43 44 return out; 45 } 46 } | Popular Tags |