I'm trying to convert "0x16" and "0b10" to decimal using "Integer.parseInt("0x16", 10)", but I keep getting this error:
Exception in thread "main" java.lang.NumberFormatException: For input string: "0x16"
I'm trying to convert "0x16" and "0b10" to decimal using "Integer.parseInt("0x16", 10)", but I keep getting this error:
Exception in thread "main" java.lang.NumberFormatException: For input string: "0x16"
First argumet of Integer.parseint function is a string which express a number, and second argumet is a base (or radix).
"0x16" is made of two parts, "0x" shows that the base is 16 and "16" shows the number in hexadecimal.
If you want to get integer value of "0x16", the code will be
int aValue;
aValue = Integer.parseint("16",16);
and then, you can show the value in decimal by following code
printf("%d" , aValue);
Points are 1. Binary, decimal and hexadecimal are formats to express integer values by strings. 2. "0x16" and "0b10" are combination of 'base' and 'value'(in string). 3. To convert combination string into integer, use Inter.parseint with 'string' as first argument and 'base' as second argument. (0x means 'base is 16', 0b means 'base is 2' etc.) Ex: "0x16" : parseint("16",16); "0b10" : parseint("10",2);