Tuesday 23 February 2016

How to convert Hex String to Integer and reverse to back?

Hello dear,
there was an situation where i had to convert hex string to integer and again integer in to hex string.
I did it in such way:

Use these given line of code and you will get same output that you want.
C# code to convert hex to int and int to hex is:

int integar32Value=  10133;
string hexValue = integar32Value.ToString("X"); // output : 2795
int intAgain = int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber); // 10133
intAgain = Convert.ToInt32(hexValue, 16); // or 10133