Topaz Filer: if you use e-mail for business, we can save you money and decrease your risk.
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...
 
Auto-following on Twitter
Ubuntu and XP on one “desktop”
 
    
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...
 
Outlook interop - stopping user properties appearing on Outlook message print
Seriously, why is “cut and paste” majorly newsworthy???
 
    
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.
Recession Busting Bespoke Software
Get through the recession by investing in bespoke software to decrease costs and create commercial opportunities.
Other DN247 Network Sites
.NET 247
SQL Server Wins
Old Skool Developer
 
Copyright © AMX Software Ltd 2008-2009. Portions copyright © Matthew Baxter-Reynolds 2001-2009. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - .NET 247 is a member of the DN247 Network - 4.0.30129.1734