Here you can find the source of toBinArray(String hexStr)
public static byte[] toBinArray(String hexStr)
//package com.java2s; //License from project: Open Source License public class Main { public static byte[] toBinArray(String hexStr) { byte bArray[] = new byte[hexStr.length() / 2]; for (int i = 0; i < (hexStr.length() / 2); i++) { byte firstNibble = Byte.parseByte(hexStr.substring(2 * i, 2 * i + 1), 16); // [x,y) byte secondNibble = Byte.parseByte(hexStr.substring(2 * i + 1, 2 * i + 2), 16); int finalByte = (secondNibble) | (firstNibble << 4); // bit-operations only with numbers, not bytes. bArray[i] = (byte) finalByte; }//w w w . j a v a2 s.co m return bArray; } }