Java - int binary number format

What is int binary number format?

All int literals in the binary number format start with 0b or 0B.

The following are examples of using int literals in the binary number format:

int num1 = 0b10101; 
int num2 = 0b00011; 
int num3 = 0b10; 
int num4 = 0b00000010; 

Demo

public class Main {
  public static void main(String[] args) {
    int num1 = 0b10101; 
    int num2 = 0b00011; 
    int num3 = 0b10; 
    int num4 = 0b00000010; 

    System.out.println(num1);//w  ww  . ja  v a  2  s. c  o  m
    System.out.println(num2);
    System.out.println(num3);
    System.out.println(num4);
  }
}

Result

Exercise