Reputation:
I have an array of strings that are in hex format, for example {"3d", "20", "5a"}
.
What would be a good way of converting each element of this string to decimal format?
I've tried using GetBytes()
, but that doesn't seem to work since it sees "3d" as two different characters because it doesn't know that it is in hex format.
GetBytes()
works fine in a situation like below but not if characters are in hex.
What am I missing here?
string a = "T";
byte[] b = {10};
b = System.Text.UTF8Encoding.Default.GetBytes(a);
Upvotes: 1
Views: 226
Reputation: 323
int decValue = int.Parse(hexValue,System.Globalization.NumberStyles.HexNumber);
Try that. HexValue is the number in hex format and decValue is in decimal...
Upvotes: 1