How to Convert Hex to Decimal in Java
The challenge
Write a function that converts an input string contains a hex
value, and return a decimal
.
Test cases
|
|
The solution in Java
In Java, it is really easy to convert Hex to Decimal.
You simply use the Integer
class and call the parseInt
method, making sure to also provide the base that you want to convert from.
As we know that the input will be a hex value, and we also know that the hexadecimal number system is a base 16 numbering system, we are able to do the following: