File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Java in General
Java Convert Hexadecimal number into Integer
Mohammed Abdul Ali
Joined: Apr 24, 2010
Apr 24, 2010 06:18:16
I am new in
programming. I am trying to convert hexadecimal number into integer and getting
error. The code sample is:
str1 = "0XA800001D";
String str2 = str1.replaceFirst("0X", "");
int value_int = Integer.parseInt( str2.trim(), 16 );
Can anybody please help me!!!
Joined: Sep 28, 2004
Apr 24, 2010 06:29:22
Java integers are signed. And that hexidecimal number is too big to fit.
Java Threads, 3rd Edition
Jini in a Nutshell
Java Gems (contributor)
Joined: Oct 27, 2005
Apr 24, 2010 07:28:21
Try using a long as intermediate result:
int value_int = (int)Long.parseLing(str2.trim(), 16);
This code will first create a long with value 2818572317, then the cast to int will turn it into -1476394979.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions
How To Answer Questions
I agree. Here's the link:
subject: Java Convert Hexadecimal number into Integer
Problem on String
Referencing to another object
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015