By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,424 Members | 1,382 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,424 IT Pros & Developers. It's quick & easy.

hex to ascii conversion

P: n/a
hi to all,

i just need to convert a hex string, let's say "00" or "16" or "FF" that i
get from a file
and display the ascii character equivalent.

How i can do this ??

thanks a lot form any help

objectref
Nov 16 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi objectref,

You can use the Convert.ToInt32(string, base) to get the number value of a
hexadecimal string

int n = Convert.ToInt32("FF", 16);

To convert it to a character, simply cast the integer to char

char c = (char)n;

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2

P: n/a
Ok, Morten,

it is workimg ok!

thanks a lot for your help! I was up to a mess with the Encoding class
thanks again!

objectref
"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:opsnfd99aaklbvpo@pbn_computer...
Hi objectref,

You can use the Convert.ToInt32(string, base) to get the number value of a
hexadecimal string

int n = Convert.ToInt32("FF", 16);

To convert it to a character, simply cast the integer to char

char c = (char)n;

--
Happy Coding!
Morten Wennevik [C# MVP]

Nov 16 '05 #3

P: n/a
Does this work?

string str = "FF";
char c= Int32.Parse(str, NumberStyles.AllowHexSpecifier);

Regards
Senthil

Nov 16 '05 #4

P: n/a
yeap!!

with a cast change:
char c= (char) Int32.Parse(str, NumberStyles.AllowHexSpecifier);

thanks a lot !
"sadhu" <se**********@wdevs.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Does this work?

string str = "FF";
char c= Int32.Parse(str, NumberStyles.AllowHexSpecifier);

Regards
Senthil

Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.