How to convert integer to hex and hex to integer in C#

1 Answer

0 votes
using System;
using System.Globalization;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = 90876;

            Console.WriteLine("{0:X}", n);
            Console.WriteLine("{0:X8}", n);

            string hex = n.ToString("X8");

            int y = int.Parse(hex, NumberStyles.AllowHexSpecifier);
            Console.WriteLine(y);
        }
    }
}


/*
run:
   
162FC
000162FC
90876
 
*/

 



answered Aug 20, 2018 by avibootz

Related questions

3 answers 501 views
1 answer 372 views
1 answer 164 views
164 views asked Mar 6, 2025 by avibootz
1 answer 197 views
1 answer 170 views
170 views asked Nov 19, 2024 by avibootz
1 answer 205 views
2 answers 285 views
...