Java – Hexadecimal

Java – Hexadecimal

Hexadecimal system is 16 based, digit can be used is from range 0 – 9 A – F.

Prefix – 0x

you can define hex number start from 0x Eg

public static void main(String[] args) {
int first = 0xA; #10
int second = 0xB; #11
int third = 0xC; #12
}

Print Decimal Value

public static void main(String[] args) {
int first = 0xA;
int second = 0xB;
int third = 0xC;

System.out.println("first " + first); //10
System.out.println("second " + second); //11
System.out.println("third " + third); //12
}

Example 1

public static void main(String[] args) {
int first = 0x14A;
System.out.println("first " + first); // 330
}

Calculation

> 1 4 A
> (1 * 16^2) + (4 * 16^1) + (10 * 16^0)
> 256 + 64 + 10
> 330

Write a Reply or Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.