Here you can find the source of toBytes4HexString(String str, char... separateds)
public static byte[] toBytes4HexString(String str, char... separateds)
//package com.java2s; //License from project: Apache License public class Main { public static byte[] toBytes4HexString(String str, char... separateds) { if (str == null) return new byte[0]; char separated = ' '; if (separateds != null && separateds.length == 1) { separated = separateds[0];/* w w w . j a v a2 s . co m*/ String[] strArr = str.split(separated + ""); byte[] array = new byte[strArr.length]; for (int i = 0; i < strArr.length; i++) { array[i] = (byte) Integer.parseInt(strArr[i], 16); } return array; } else { byte[] array = new byte[str.length() / 2]; int beginIndex = 0; for (int i = 0; beginIndex < str.length(); i++) { array[i] = (byte) Integer.parseInt(str.substring(beginIndex, beginIndex + 2), 16); beginIndex += 2; } return array; } } }