Function binary() has a 2nd parameter where we can specify how many digits we need:
We can combine that w/ Integer.numberOfLeadingZeros() in order to know how many digits to remove outta total max of 32 bits:
for (int i = 0; i < 05000; i += 32) {
final int digits = max(1, Integer.SIZE - Integer.numberOfLeadingZeros(i));
println(i, TAB, binary(i, digits));
}
exit();
0 0
32 100000
64 1000000
96 1100000
128 10000000
160 10100000
192 11000000
224 11100000
256 100000000
288 100100000
320 101000000
352 101100000
384 110000000
416 110100000
448 111000000
480 111100000
512 1000000000
544 1000100000
576 1001000000
608 1001100000
640 1010000000
672 1010100000
704 1011000000
736 1011100000
768 1100000000
800 1100100000
832 1101000000
864 1101100000
896 1110000000
928 1110100000
960 1111000000
992 1111100000
1024 10000000000
1056 10000100000
1088 10001000000
1120 10001100000
1152 10010000000
1184 10010100000
1216 10011000000
1248 10011100000
1280 10100000000
1312 10100100000
1344 10101000000
1376 10101100000
1408 10110000000
1440 10110100000
1472 10111000000
1504 10111100000
1536 11000000000
1568 11000100000
1600 11001000000
1632 11001100000
1664 11010000000
1696 11010100000
1728 11011000000
1760 11011100000
1792 11100000000
1824 11100100000
1856 11101000000
1888 11101100000
1920 11110000000
1952 11110100000
1984 11111000000
2016 11111100000
2048 100000000000
2080 100000100000
2112 100001000000
2144 100001100000
2176 100010000000
2208 100010100000
2240 100011000000
2272 100011100000
2304 100100000000
2336 100100100000
2368 100101000000
2400 100101100000
2432 100110000000
2464 100110100000
2496 100111000000
2528 100111100000