Hex function

J

Joshua Ellul

Hi,

Can anyone tell me if there is a function in C# that will return a value in
Hex format? Similiar to the Hex function of vb.

Regards,

Josh
 
I

Imran Koradia

you could use the ToString function:

int myVal = 171;

// this will give you 0xAB
str myValHex = myVal.ToString("X");

hope that helps..
Imran.
 
I

Ivar

Try

/// <summary>
/// Converts specified string to hexa string.
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
public static string Hex(string text)
{
return
BitConverter.ToString(Encoding.Default.GetBytes(text)).ToLower().Replace("-","");
}
 
S

SB

This may help:

int i = 2987382;
string hexval = i.ToString("X8"); // X indicated uppercase hex, 8 = show
8 places

For more info, see IntXX.ToString and the NumberFormatInfo class in the
online help.

HTH,
-sb
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top