Here you can find the source of ToByteArray(String hexString)
public static byte[] ToByteArray(String hexString)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; public class Main { public static byte[] ToByteArray(String hexString) { final String[] hexChunks = hexString.replace(" ", "").split("(?<=\\G..)"); byte[] result = new byte[hexChunks.length]; for (int i = 0; i < hexChunks.length; i++) { result[i] = (byte) Integer.parseInt(hexChunks[i], 16); }/*from ww w .j a v a2 s . c o m*/ return result; } public static byte[] ToByteArray(int i) { return ByteBuffer.allocate(4).putInt(i).array(); } }