aspose file tools*
The moose likes Java in General and the fly likes Need Help for Converting a Hex String to an Integer in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Need Help for Converting a Hex String to an Integer in Java" Watch "Need Help for Converting a Hex String to an Integer in Java" New topic
Author

Need Help for Converting a Hex String to an Integer in Java

Sam Saha
Ranch Hand

Joined: Jan 23, 2010
Posts: 104
Hi

I am trying to convert a Hex String to Integer. But I am getting NumberFormatException when I run the code. I would appreciate if someone can help me so that I can convert the whole string into number.

My code:

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39884
    
  28
What is the largest hex number which will fit into an int?
Sam Saha
Ranch Hand

Joined: Jan 23, 2010
Posts: 104
"000016A100"
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14352
    
  22

So you understand that the number 16A10000006800000000 is too large to fit in an int. You should use a long instead.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39884
    
  28
Sam Saha wrote:"000016A100"
No it isn’t. It is 0x7fffffff.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39884
    
  28
More details of the limits in the Java Language Specification. You have to scroll down a bit to find it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need Help for Converting a Hex String to an Integer in Java