Hexadecimal formatting with leading zeros?!

Discussion in 'ASP .Net' started by Dmitry Bond., Oct 13, 2005.

  1. Dmitry Bond.

    Dmitry Bond. Guest

    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.
     
    Dmitry Bond., Oct 13, 2005
    #1
    1. Advertising

  2. Dmitry Bond.

    Oliver Sturm Guest

    Dmitry Bond. wrote:

    >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)
     
    Oliver Sturm, Oct 13, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luke Zhang [MSFT]

    Re: CSV for Excel - Problem with Leading Zeros

    Luke Zhang [MSFT], Jun 26, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    2,262
    Luke Zhang [MSFT]
    Jun 26, 2003
  2. GIMME
    Replies:
    5
    Views:
    43,835
    Dale King
    Feb 13, 2004
  3. r.magdeburg

    leading zeros - wrong int

    r.magdeburg, Dec 1, 2003, in forum: C++
    Replies:
    2
    Views:
    1,750
    red floyd
    Dec 1, 2003
  4. Stian
    Replies:
    2
    Views:
    648
    Thomas D'Tak
    Sep 19, 2004
  5. Tom Reinhart

    Formatting date without leading zeros

    Tom Reinhart, May 15, 2005, in forum: Ruby
    Replies:
    10
    Views:
    309
    tony summerfelt
    May 15, 2005
Loading...

Share This Page