How to convert numbers between hexadecimal and decimal

To convert from decimal to hex do…

string hexValue = decValue.ToString("X");

To convert from hex to decimal do either…

int decValue = int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber);

or

int decValue = Convert.ToInt32(hexValue, 16);

Leave a Comment