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

1 Answer

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

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





/*
run:

0000000000010001

*/

 



answered Jan 9, 2023 by avibootz

Related questions

1 answer 118 views
1 answer 105 views
1 answer 138 views
2 answers 134 views
1 answer 112 views
...