C# Program to write a number in hexadecimal format

CsharpProgrammingServer Side Programming

Let’s say the following is the number −

int a = 12250;

You can work around the following ways to get a number in hexadecimal format −

{0:x}
{0:x8}
{0:X}
{0:X8}

Here is the code −

Example

 Live Demo

using System;
class Demo {
   static void Main() {
      int a = 12250;
      Console.WriteLine("{0:x}", a);
      Console.WriteLine("{0:x8}", a);
      Console.WriteLine("{0:X}", a);
      Console.WriteLine("{0:X8}", a);
   }
}

Output

2fda
00002fda
2FDA
00002FDA
raja
Published on 05-Sep-2018 08:49:02
Advertisements