I need to convert hexadecimal value which is OX12 to decimal in JAVA,
as I knew hexadecimal is based 16 (1..9, a..f), but in this case, I don't know how to convert with that value.
Can someone help me?
Thanks so much
If the number is a String
, you can use the parseInt
method of the Integer
class with first argument "12"
(the number in hex) and second argument 16
, the radix, or base, of the number
int number = Integer.parseInt("12", 16);
System.out.println(number);
// output is 18
If the number is not a String
, you can simply do the following:
int number = 0x12;
System.out.println(number);
// output is 18