Represent Int32 as a Hexadecimal String in C#


To represent Int32 as a Hexadecimal string in C#, use the ToString() method and set the base as the ToString() method’s second parameter i.e. 16 for Hexadecimal.

Int32 represents a 32-bit signed integer.

Firstly, set an Int32 variable.

int val = 9898;

Now, convert it to a hexadecimal string by including 16 as the second parameter.

Convert.ToString(val, 16)

Example

 Live Demo

using System;
class Demo {
   static void Main() {
      int val = 9898;
      Console.WriteLine("Integer: "+val);
      Console.Write("Hex String: "+Convert.ToString(val, 16));
   }
}

Output

Integer: 9898
Hex String: 26aa

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 23-Jun-2020

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements