Re: How to show a string with hexadecimal integer included?

Discussion in 'C Programming' started by Martin Ambuhl, Jun 26, 2003.

  1. Christopher Culver <> wrote
    (25 Jun 2003) in news:
    / comp.lang.c:

    > printf("This is a hex number: %x", hexNumber)
    >
    > but this results in only the minimum number of digits being displayed,
    > i.e. "7e" instead of "0x007e". Is there anything I can use in place of
    > %x which will display the fully qualified hexadecimal number?


    #include <stdio.h>

    int main(void)
    {
    unsigned hexNumber = 0x7e;
    printf("[output]\nThis is a hex number: %#06x\n", hexNumber);
    return 0;
    }

    [output]
    This is a hex number: 0x007e


    --
    Martin Ambuhl
    Returning soon to the
    Fourth Largest City in America
    Martin Ambuhl, Jun 26, 2003
    #1
    1. Advertising

  2. Martin Ambuhl

    Dan Pop Guest

    In <Xns93A5C8668263mambuhlearthlinknet@207.217.77.26> Martin Ambuhl <> writes:

    >Christopher Culver <> wrote
    >(25 Jun 2003) in news:
    >/ comp.lang.c:
    >
    >> printf("This is a hex number: %x", hexNumber)
    >>
    >> but this results in only the minimum number of digits being displayed,
    >> i.e. "7e" instead of "0x007e". Is there anything I can use in place of
    >> %x which will display the fully qualified hexadecimal number?

    >
    >#include <stdio.h>
    >
    >int main(void)
    >{
    > unsigned hexNumber = 0x7e;
    > printf("[output]\nThis is a hex number: %#06x\n", hexNumber);


    IMHO, it is more practical to use %#.4x for the job. No need to bother
    counting the prefix characters.

    Dan
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
    Dan Pop, Jun 26, 2003
    #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. Derk Gwen
    Replies:
    3
    Views:
    1,312
    Zoran Cutura
    Jun 26, 2003
  2. bd
    Replies:
    0
    Views:
    674
  3. Replies:
    15
    Views:
    11,947
    Eric Sosman
    Jun 23, 2006
  4. tobleron
    Replies:
    9
    Views:
    12,707
    Martin Gregorie
    Oct 27, 2008
  5. Randy Kramer
    Replies:
    12
    Views:
    374
    Robert Klemme
    Oct 25, 2007
Loading...

Share This Page