I am trying to convert a byte value to binary for data transfer. Basically, I am sending a value like \"AC\" in binary (\"10101100\") in a byte array where \"10101100\" is a
Alternative to @LINEMAN78s solution is:
public byte[] getByteByString(String byteString){
return new BigInteger(byteString, 2).toByteArray();
}
public String getStringByByte(byte[] bytes){
StringBuilder ret = new StringBuilder();
if(bytes != null){
for (byte b : bytes) {
ret.append(Integer.toBinaryString(b & 255 | 256).substring(1));
}
}
return ret.toString();
}