I have a string containing a hexadecimal value. Now I need the content of this string containing the hexadecimal as a byte variable. How should I do this without changing the hexadecimal value?
-
stackoverflow.com/questions/311165/…Dialecticus– Dialecticus2011-02-13 18:02:07 +00:00Commented Feb 13, 2011 at 18:02
-
Not a duplicate (wrt C#) as far as I can tell. There are many variations, but this is specific ("xx" -> byte) and warrants a simpler answer than a number of the more complex scenarios.user166390– user1663902011-02-13 19:14:00 +00:00Commented Feb 13, 2011 at 19:14
Add a comment
|
3 Answers
An alternative to the options posted so far:
byte b = Convert.ToByte(text, 16);
Note that this will return 0 if text is null; that may or may not be the result you want.
1 Comment
brunnerh
Damn, i even looked at the
Convert.ToByte method but totally didn't spot that overload which takes the base as parameter...