C# Hexadecimal ("X") Format Specifier

ProgrammingServer Side ProgrammingCsharp

The hexadecimal ("X") format specifier is used to convert a number to a string of hexadecimal digits.

Set the case of the format specifier for uppercase or lowercase characters to be worked on hexadecimal digits greater than 9.

Let us understand this with an example −

“X” for PQR, whereas “x” for pqr

Example

 Live Demo

using System;
using System.Numerics;
using System.Globalization;
class Demo {
   static void Main() {
      int num;
      num = 345672832;
      Console.WriteLine(num.ToString("X"));
      Console.WriteLine(num.ToString("X2"));
      num = 0x307e;
      Console.WriteLine(num.ToString("x"));
      Console.WriteLine(num.ToString("X"));
   }
}

Output

149A8C80
149A8C80
307e
307E
raja
Published on 11-Sep-2018 12:15:26
Advertisements