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 321 views
1 answer 267 views
1 answer 68 views
1 answer 95 views
1 answer 72 views
72 views asked Nov 19, 2024 by avibootz
1 answer 103 views
2 answers 146 views
...