display a hexadecimal number

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'd like to display a byte as a hex, using C# String.Format() function. I
also would like for the number to have a leading 0 if it's represented by
one digit only.

byte bt1 = 0x09;
byte bt2 = 0x0A;

Console.WriteLine(String.Format("{0:00}", bt1)); // displays 09, but it's a
decimal
Console.WriteLine(String.Format("{0:X}", bt2)); // displays A, but without
the leading 0


How can I combine these two formatters?

Thanks,
VR
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top