Reputation: 1888
I know in java we can't deal with bit directly, I want to know how can we convert an byte array[] to byte. Such that
String bytestr="00000011";
byte[] noofbytes=bytestr.getBytes();
byte convbyte=(noofbytes[]) to byte
Is it possible ? does any one have any idea ? Thanks.
Upvotes: 1
Views: 96
Reputation: 1074495
I think you mean bits, not bytes.
String bitstr = "00000011";
byte convbyte = Byte.parseByte(bitstr, 2);
The , 2
tells it that you're parsing a binary (base 2) string; the default would be decimal (base 10).
Upvotes: 5