How to Convert Integer to Hex and Vice versa in C# ?

Published on June 7, 2015 by abundantcode

Filed under Foundation (General)

Last modified June 7, 2015

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 2002 times

If you want to convert an integer value to a hexa decimal value in C# and hexa decimal value to integer , you can use the “X” string formatting specifiers and the int.parse method with the method over loading option.

How to Convert Integer to Hex and Vice versa in C# ?

The code snippet to demonstrate the conversion of the integer value to hexa decimal and vice versa (hexadecimal to integer) is below.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace AbundantcodeConsoleApp
    class Program
        static void Main(string[] args)
            int decimalInput = 10;
            // Convert decimal value 10 to hexadecimal
            string hexaDecimalValue = decimalInput.ToString("X");
            // Convert the hexadecimal value to number
            int DecimalOutput = int.Parse(hexaDecimalValue, System.Globalization.NumberStyles.HexNumber);
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Comment