Reputation: 221
When i run this code it gives NumberFormatException? how do i convert A49D43C5 this numbers to decimal in java?
logger.info("Decimal value: " + Integer.parseInt("A49D43C5", 16));
Upvotes: 2
Views: 1328
Reputation: 1567
Integer
's max value is 2147483647.
try to use BigInteger
for your hexadecimal.
BigInteger bigInt = new BigInteger(hexString, 16);
Upvotes: 0
Reputation: 201447
That number is larger than an int
(Integer.MAX_VALUE
is 231 - 1 or 2147483647
). You could use a long
like
System.out.println("Decimal value: " + Long.parseLong("A49D43C5", 16));
Output is
Decimal value: 2761769925
Upvotes: 1