Hex formatting in a string?

  • Thread starter Thread starter xlar54
  • Start date Start date
X

xlar54

Hey folks, how can I format a hex string to display as such:

instead of:

10
130


I want the leading values for a full 16 bit address as in:

0010
0130

etc.

Convert.ToString(16, 16) just gives me "10", when I really want "0010".
Id like to use a formatter if there is one for this, otherwise i have
to get into string manipulation, which Id rather avoid.
 
Hi,
you can do the following:

string x = 16.ToString("X4");

which will produce "0010"

Mark
 
If you just have a string to begi with and not an integer, you can use:

string x = "101".PadLeft(4, '0');

Mark
 
Back
Top