when converting int to binary, how to output it to 8 character, currently it only display 1 and short of the 7 zeros
int x = 1;
String bin = Integer.toBinaryString(x);
System.Out.Println(bin);
example output to 0000 0001
I am not sure if that is what you mean but how about something like
String.format("%8s", Integer.toBinaryString(1)).replace(' ', '0')
will generate 00000001
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With