What am I missing here ?

  • Thread starter Thread starter Gary Stark
  • Start date Start date
G

Gary Stark

I'm sure that this is something very simple.

I need to convert a string of a decimal number to a string of the
equivalent hex value so that "10" should equate to "0A", and so on.

With the following code

int nLen;
string cRet;

nLen = 10
cRet = int.Parse( nLen.ToString(),
System.Globalization.NumberStyles.HexNumber );

cRet is assigned a value of "16". I'm reading into this that the value
is being treated as if it's already a hex value, and is being converted
back to decimal - the reverse of what I want to do.

What am I missing here? Nothing is jumping out at me from the help
files. What class and method do I use for this?
 
Gary,
I need to convert a string of a decimal number to a string of the
equivalent hex value so that "10" should equate to "0A", and so on.

Try

Int32.Parse( "10" ).ToString( "X" );

Pad with zeros as needed.



Mattias
 
Gary Stark said:
What am I missing here? Nothing is jumping out at me from the help
files. What class and method do I use for this?

Why are you parsing at all? All you need is formatting:

int nLen = 10;
string cRet = int.ToString ("X");
 
Back
Top