This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

please review- NumberFormatException in Conversation of String to Hexadecimal

 
Babu Singh
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




Ouput:
java.lang.NumberFormatException: For input string: "0cv"
 
Omar Al Kababji
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Babu Singh
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Sir,

thank you to resolve my queries.


 
Omar Al Kababji
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic