C# Hexadecimal ("X") Format Specifier



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
Samual Sam
Samual Sam

Learning faster. Every day.


Advertisements