Java - int hexadecimal number format

What is int hexadecimal number format?

All int literals in the hexadecimal number format start with 0x or 0X and they must have at least one more hexadecimal digit.

Hexadecimal number format uses 16 digits, 0-9 and A-F (or a-f).

The case of the letters A to F does not matter.

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

  
int num1 = 0x123; 
int num2 = 0xdecafe; 
int num3 = 0x1A2B; 
int num4 = 0X0123; 
int num5 = 0XDEAD; 
int num6 = 0Xdead;
int num7 = 0Xfade;

Demo

public class Main {
  public static void main(String[] args) {
    int num1 = 0x123; 
    int num2 = 0xdecafe; 
    int num3 = 0x1A2B; 
    int num4 = 0X0123; 
    int num5 = 0XDEAD; 
    int num6 = 0Xdead;
    int num7 = 0Xfade;
    System.out.println(num1);//ww  w.j ava2s . c o m
    System.out.println(num2);
    System.out.println(num3);
    System.out.println(num4);
    System.out.println(num5);
    System.out.println(num6);
    System.out.println(num7);
  }
}

Result

Exercise