I have a byte array that I would like to print in binary.I could loop through the array and concatenate Integer.toString(byteArray[i], 2)
or Integer.toBinaryString
to a string, but any bytes that start with a 0 will have that 0 trimmed off. How can I avoid this?
For example, if the array were:
{0b11110000, 0b10101010, 0b11001100, 0b00001111}
I would get:
1111000010101010110011001111 // what is printed
11110000101010101100110000001111 // what I want
// 0's are missing ^--^