469,266 Members | 1,768 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,266 developers. It's quick & easy.

hex to ascii conversion

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
4 56683
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
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
Does this work?

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

Regards
Senthil

Nov 16 '05 #4
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.

Similar topics

7 posts views Thread by Zach | last post: by
reply views Thread by Mike | last post: by
1 post views Thread by Aparna Sinha via .NET 247 | last post: by
reply views Thread by Jon Paal | last post: by
3 posts views Thread by AlekseyUS | last post: by
14 posts views Thread by Peter Sprenger | last post: by
1 post views Thread by Vic | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.