Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change hexadecimal value to double

Status
Not open for further replies.

hallian92

Programmer
Jul 30, 2002
8
US
Is there a way that I can convert the following hexadecimal value into double:

String s = "16#1234#";

As converting this to long I am doing this
if (s.startsWith("16#") && s.endsWith("#"))
{
extractedValue = s.substring( 3, s.length()-1 );
longValue = Long.parseLong( extractedValue, 16 );
}


Is there any way I can do the same and change the above to double. If I use
doubleValue = Double.parseDouble(s);

gives me an error so I want to parse the above value and change it to double any tips of work arround. Is there any way that I change the string to double with a specified radix as there are no such methods like parseLong or parseInt that also except readix.
Thanks
 
I should have wrote the same code exept for cuttin your string :
Code:
String s = "16#1234#";

// As converting this to long I am doing this
StringTokenizer st = new StringTokenizer(s, "#");
if (st.countTokens() == 2) {
   int radix= new Integer(st.nextToken()).intValue();
   String hexStr = st.nextToken();
   longValue = Long.parseLong( hexStr, radix );
}

hope that helps. Water is not bad as soon as it stays out human body ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top