How to print the bits of an integer in 8 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("%8s", Integer.toBinaryString(num)).replaceAll(" ", "0"));
    }
}





/*
run:

00010001

*/

 



answered Jan 9, 2023 by avibootz

Related questions

1 answer 124 views
1 answer 110 views
1 answer 101 views
1 answer 104 views
1 answer 102 views
...