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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
AlanRank #669 · 3.6K reputationPosted Sep 17, 2008, 2:56 AM EDT
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);
}
jeevan mummadi140 reputationPosted Sep 17, 2008, 3:18 AM EDT
thank u allan,
hex[i] = dec[i].ToString("x2");
i think x2 means string format
plz give me explanation abt x2
AlanRank #669 · 3.6K reputationPosted Sep 17, 2008, 5:54 AM EDT
'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 mummadi140 reputationPosted Sep 17, 2008, 8:47 PM EDT