How to print the bits of an integer in 32 bit format with Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        int num = 238;

        System.out.println(String.format("%32s", Integer.toBinaryString(num)).replaceAll(" ", "0"));
    }
}





/*
run:

00000000000000000000000011101110

*/

 



answered Jan 9, 2023 by avibootz

Related questions

1 answer 150 views
2 answers 269 views
1 answer 144 views
1 answer 140 views
1 answer 119 views
...