Multimobile Development: Building Applications for any Smartphone
Convert hex strings to string, float, int and double
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.


Uwe Kuhne
Before I start my question, I wish all, a really happy new year. May your
wishes for 2004 come true.

Now my question:
I've an export from a proprietary old db system, which exports the data in
hexadecimal representation.

I would like to have methods like
- HexToString ("...hexadecimal string...")
- HexToInt ("...hexadecimal string...")
- HexToFloat ("...hexadecimal string...")
- HexToDouble ("...hexadecimal string...")
which converts me a hexadecimal string to the according type.

I want to give the hex string as a whole to the method e.g.
- HexToString ("3139383530323038") and not
- HexToString("\x31\x39\x38\x35\x30\x32\x30\x38")

Are there any classes in the .NET framework, which can convert hexadecimal
data in the way I would like ? If not, are there any suggestion how to
solve my problem in a different way without doing all this decoding on my
own ?
In addition I know that e.g. a float is represented according to IEEE-754
(whatever this exactly means).

Thanks for help
Uwe

Reply to this message...
Vote that this is a GOOD answer...
 
Really good experience at the Apple Store
MonoDroid – looking *awesome*
 
    
Dolly
..NET doesn't really provide functions for hex to int etc
conversions, Best would be to write your own.

Refer http://www.experts-
exchange.com/Programming/Programming_Languages/Visual_Basic
/Q_20794476.html for a similar discussion.

There is some code you can use from :

http://www.codeproject.com/csharp/hexencoding.asp?
print=true
Reply to this message...
Vote that this is a GOOD answer...
 
First volume of Multimobile Development nearly ready to go to press
A mention on Developing for the iPhone and Android: The pros and cons
 
    
Nick Malik
Fairly simple really. Support is built right in

C# code:

using System.Globalization;

static long hextolong(string hex1)
{
return long.Parse(hex1, NumberStyles.AllowHexSpecifier);
}
static int hextoint(string hex1)
{
return int.Parse(hex1, NumberStyles.AllowHexSpecifier);
}
static string inttohex( int intval )
{
return intval.ToString("X");
}
static string longtohex( long longval )
{
return longval.ToString("X");
}

note: the inttohex() and longtohex() functions above will not pad your
string with leading zeros. If you want it padded, you will need to add the
leading zeros to the format specifier in the ToString() calls.

Hope this helps.

--- Nick

"Uwe Kuhne" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
 
 
System.Globalization.NumberStyles




Ad
BootFX
Reliable and powerful .NET application framework.
iOS, Android and Windows Phone Development Training and Consultancy
Hosted by RackSRV Communications
 
Multimobile Development: Building Applications for any Smartphone
Copyright © AMX Software Ltd 2008-2010. Portions copyright © Matthew Baxter-Reynolds 2001-2010. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - 4.0.30129.1734