Hexadecimal formatting with leading zeros?!

D

Dmitry Bond.

Hi All.

Is it possible to convert a byte to hexadecimal string with leading zero in
C#?
Unfortunately I not found any samples how to do it in .Net. :-(

For decimal numbers I could use String.Format("{0:0#}") or ToString("#0")
but what should I use to obtain hexadecimal representation of a number?

Is it possible at all?
Or should I use ugly constructions like:

string s = b.ToString("X");
if (s.Length == 1) s = "0" + s;

?

WBR,
Dmitry.
 
O

Oliver Sturm

Dmitry said:
Is it possible to convert a byte to hexadecimal string with leading zero in
C#?
Unfortunately I not found any samples how to do it in .Net. :-(

For decimal numbers I could use String.Format("{0:0#}") or ToString("#0")
but what should I use to obtain hexadecimal representation of a number?

Is it possible at all?

Sure, just use X2 to get a two digit hex number, for example.


Oliver Sturm
 

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

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top