How to convert a hex number (in a string variable) to a byte.

P

Pubs

Hi,

I have a variable, a string that contains a hex number (max is FF).
I want to convert it to a byte value. Could some one let me know how
is it to be done. I have seen conversion of direct numbers but it does
not work in this case.


Pubudu
 
J

Jon Skeet [C# MVP]

Pubs said:
I have a variable, a string that contains a hex number (max is FF).
I want to convert it to a byte value. Could some one let me know how
is it to be done. I have seen conversion of direct numbers but it does
not work in this case.

Convert.ToByte(text, 16);
 
Q

qglyirnyfgfo

Yet another way:

byte b = byte.Parse("FF",
System.Globalization.NumberStyles.HexNumber);
 
P

Pubs

Yet another way:

byte b = byte.Parse("FF",
System.Globalization.NumberStyles.HexNumber);





- Show quoted text -

Hi all,

Thank you every body for the help. It works great now.

Pubudu
 

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