M Hamza Javed
M Hamza Javed

Reputation: 1265

java.lang.NumberFormatException: For input string: "A3ADF30029011F"

I'm trying ton convert Hex into decimal and into binary but getting same error for given HEX "001F012900F3ADA3" but same hex is converted to decimal and into binary using any online convertor.

Integer.parseInt("001F012900F3ADA3",16);   // to decimal conversion

Integer.toBinaryString(Integer.parseInt("001F012900F3ADA3", 16));   // to binary conversion

when i use part of this HEX like Integer.parseInt("00F3ADA3",16); this works fine no exception. is there some type of max hex length allowed to convert or i'm using something wrong please correct me.

Upvotes: 0

Views: 143

Answers (2)

Rance Liu
Rance Liu

Reputation: 13

The max value of int is 2147483647, value : 001F012900F3ADA3 convert to the Binary number is 8726999899286947.

Upvotes: 1

Mirek Pluta
Mirek Pluta

Reputation: 8003

The value that you're trying to parse is too big to fit in integer. To parse this properly you'd have to parse it as long.

If you replace it with below, then it'll work.

Long.toBinaryString(Long.parseLong("001F012900F3ADA3", 16));

Upvotes: 4

Related Questions