For example, the bits in a byte B
are 10000010
, how can I assign the bits to the string str
literally, that is, str = "10000010"
.
Edit
I read the byte from a binary file, and stored in the byte array B
. I use System.out.println(Integer.toBinaryString(B[i]))
. the problem is
(a) when the bits begin with (leftmost) 1, the output is not correct because it converts B[i]
to a negative int value.
(b) if the bits begin with 0
, the output ignore 0
, for example, assume B[0]
has 00000001, the output is 1
instead of 00000001
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…