How to convert binary string to the byte array of 2 bytes in java
问题 I have binary string String A = "1000000110101110" . I want to convert this string into byte array of length 2 in java I have taken the help of this link I have tried to convert it into byte by various ways I have converted that string into decimal first and then apply the code to store into the byte array int aInt = Integer.parseInt(A, 2); byte[] xByte = new byte[2]; xByte[0] = (byte) ((aInt >> 8) & 0XFF); xByte[1] = (byte) (aInt & 0XFF); System.arraycopy(xByte, 0, record, 0, xByte.length);