user3600025
user3600025

Reputation:

Converting hex to decimal

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

Answers (2)

Anonymous
Anonymous

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

Use int.Parse with NumberStyles.HexNumber.

Upvotes: 4

Related Questions