0

I want to translate a value to hex but the results are missing.

        int q = 0006038738;
        var w = q.ToString("X");
        //result: 5C24D2
        //I want that: 005C24D2

How do I incorporate the 0s at the beginning of the value I will convert?

glow grap
  • 35
  • 6
  • Related to a X4 question: https://stackoverflow.com/questions/4690480/int-to-hex-string/4690504. not exactly a dupe but a lot of question about X2 and X4 . – xdtTransform Apr 17 '19 at 11:24

1 Answers1

1

Try this:

var w = q.ToString("X8");

The precision specifier indicates the minimum number of digits desired in the resulting string. If required, the number is padded with zeros to its left to produce the number of digits given by the precision specifier.

Reference: The Hexadecimal ("X") Format Specifier

SᴇM
  • 7,024
  • 3
  • 24
  • 41