HighTechTalks DotNet Forums  

Hexadecimal formatting with leading zeros?!

Dotnet FAQs microsoft.public.dotnet.faqs


Discuss Hexadecimal formatting with leading zeros?! in the Dotnet FAQs forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Dmitry Bond.
 
Posts: n/a

Default Hexadecimal formatting with leading zeros?! - 10-13-2005 , 03:54 AM






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.



Reply With Quote
  #2  
Old   
Oliver Sturm
 
Posts: n/a

Default Re: Hexadecimal formatting with leading zeros?! - 10-13-2005 , 04:55 AM






Dmitry Bond. wrote:

Quote:
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
--
Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.