.NET FAQs Unleashed!
 
    
    

How to output an int type as a hexadecimal string?

See the code example below:

Int j = 256;
String s = j.ToString(“X”);

The value X instructs the output to be in hexadecimal format. The output would be:

100

Note that 100 is the hexadecimal (a number with base 16) equivalent of the number 256 with base 10.

If we want to set the precision of characters in the output format, we can add a number to the X. For example

string s1 = j.ToString(“X5”);

would display

00100

Definition   Display 5555 as 0005555   Initialize string from a char[]   Format decimal as currency   Output int type as hexadecimal string   Display a number in exponential   Display a number as a percent   Is String a reference type   ToString("F2")    @ before double quotes   Carriage return   Escape Sequence Why do we use backslash characters with strings?   String VS. string   \u0042\u0041\u0044  

More Interview Questions.....