Convert from decimal to hex and hex to decimal in C#.net

Convert DECIMAL TO HEX and HEX TO DECIMAIL

In this post, we can see how we can convert Decimal to hex and hex to decimal.

Code:

// Store 255 in int

int decValue = 255;

// Convert int 255 as a hex in a string variable

string hexValue = decValue.ToString(“X”);

// Convert the hex string back to the number

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

I hope this post is useful for you, If any better way is there then this please let me know.

Thanks,
Naga Harish.

  • David

    Hi guys,
    Pretty good!
    David

  • O so that how its done, so simple!