0

I am currently trying to convert integers into a binary string. However, I need each binary "group" to be exactly 8 bits or 1 byte.

For example, Integer.toBinaryString(17) will give me "10001" where instead I need "00010001"

Is there some method I can use, or possibly a simpler solution outside of hard-coding the outputs?

1 Answers1

0

Easiest is to use format strings

String.format("%08s",Integer.toBinaryString(i));

Actually this tells the formatter to pad the string with zeroes to make 8 digits