Anand Kadhi
Anand Kadhi

Reputation: 1888

byte array[] to byte is it possible in java?

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

Answers (1)

T.J. Crowder
T.J. Crowder

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

Related Questions