How to convert int number to hexadecimal number in C#

2 Answers

0 votes
using System;

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

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

            Console.WriteLine();

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

            Console.WriteLine();

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


/*
run:
     
17fa5
17fa5

17FA5
17FA5

017FA5
00017FA5

*/

 



answered Dec 23, 2016 by avibootz
0 votes
using System;

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

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

            Console.WriteLine(hex);
        }
    }
}


/*
run:
     
017FA5

*/

 



answered Dec 23, 2016 by avibootz

Related questions

1 answer 169 views
1 answer 133 views
1 answer 125 views
1 answer 191 views
2 answers 285 views
...