| Author |
please review- NumberFormatException in Conversation of String to Hexadecimal
|
Babu Singh
Ranch Hand
Joined: Aug 17, 2009
Posts: 68
|
|
Ouput:
java.lang.NumberFormatException: For input string: "0cv"
|
 |
Omar Al Kababji
Ranch Hand
Joined: Jan 13, 2009
Posts: 357
|
|
I think you need to learn a bit about Hex numbers
0 1 2 3 4 5 6 7 8 9 A B C D E F
there is no V in a hex number, so you get the exception.
|
Omar Al Kababji - Electrical & Computer Engineer
[SCJP - 90% - Story] [SCWCD - 94% - Story] [SCBCD - 80% - Story] | My Blog
|
 |
Babu Singh
Ranch Hand
Joined: Aug 17, 2009
Posts: 68
|
|
Dear Sir,
thanks for your reply.
when i give input String s = "12345678";
Output is: Hex Value of: 12345678 = 305419896
when i give input String s = "123456789";
Output is: java.lang.NumberFormaatException: For input string: "123456789"
|
 |
Omar Al Kababji
Ranch Hand
Joined: Jan 13, 2009
Posts: 357
|
|
ok this is another issue now your problem is that
123456789 Hex = 4886718345 in Decimal and this value is too big to fit in an integer, so use a long instead of int
Long.parseLong();
|
 |
Babu Singh
Ranch Hand
Joined: Aug 17, 2009
Posts: 68
|
|
Dear Sir,
thank you to resolve my queries.
|
 |
Omar Al Kababji
Ranch Hand
Joined: Jan 13, 2009
Posts: 357
|
|
No problem
|
 |
 |
|
|
subject: please review- NumberFormatException in Conversation of String to Hexadecimal
|
|
|