Alon Gubkin
Alon Gubkin

Reputation: 57119

In C#, How to convert a hexdecimal string to int?

How do I convert the following string:

6F

for example, to a normal int? It's hexdecimal value.

Thanks.

Upvotes: 4

Views: 283

Answers (3)

almog.ori
almog.ori

Reputation: 7889

Convert.ToInt32(stringValue,16);

Where last param is base of 16

Upvotes: 2

Travis
Travis

Reputation: 2180

 int num = Int32.Parse(strValue, System.Globalization.NumberStyles.HexNumber);

Upvotes: 5

jason
jason

Reputation: 241583

string s = "6F";
int i = Int32.Parse(s, NumberStyles.AllowHexSpecifier);
Console.WriteLine(i); // prints "111" to the console

For details on NumberStyles, see MSDN.

Upvotes: 11

Related Questions