Turn byte into two-digit hexadecimal number just using ToString?

61,178

myByte.ToString("X2") I believe.

Share:
61,178
ssss
Author by

ssss

Expert in: C#, .NET/IL, JavaScript, HTML/CSS, Unicode; extensive experience with: SQL, Perl, PHP, Delphi, protocols such as HTTP, SMTP, etc.; less experience with: Java, C/C++

Updated on August 06, 2020

Comments

  • ssss
    ssss almost 4 years

    I can turn a byte into a hexadecimal number like this:

    myByte.ToString("X")
    

    but it will have only one digit if it is less than 0x10. I need it with a leading zero. Is there a format string that makes it possible to do this in a single call to ToString?