dec =
Encoding.ASCII.GetBytes(name);i convert string to ascii value i want convert ascii to hexa value plz help
dec =
Encoding.ASCII.GetBytes(name);i convert string to ascii value i want convert ascii to hexa value plz help
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
jeevan mummadiPosted Sep 18, 2008, 12:47 AM
AlanPosted Sep 17, 2008, 9:54 AM
'x' or 'x' means express the number in hexadecimal string format. If it's a lower case 'x', then the hex digits higher than 9 (i.e. abcdef) appear in lower case . If it's an upper case 'X', then they appear as 'ABCDEF'.
The '2' means express as (at least) two hex digits and use a leading zero if there's only one digit required to express the number. For example decimal 15 would be expressed as 0F using the 'X2' format.
jeevan mummadiPosted Sep 17, 2008, 7:18 AM
thank u allan,
hex[i] = dec[i].ToString("x2");
i think x2 means string format
plz give me explanation abt x2
AlanPosted Sep 17, 2008, 6:56 AM
Try this:
string name = "abcdef";
byte[] dec = new byte[name.Length];
string[] hex = new string[name.Length];
dec = Encoding.ASCII.GetBytes(name);
for(int i = 0; i < dec.Length ; i++)
{
hex[i] = dec[i].ToString("X2");
}
foreach(string h in hex)
{
Console.Write("{0} ", h);
}