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

Discussion in 'C Programming' started by Derk Gwen, Jun 26, 2003.

  1. Derk Gwen

    Derk Gwen Guest

    Christopher Culver <> wrote:
    # I have a string which should include a hexadecimal number. I've tried %x
    # like this:
    #
    # 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?

    %04x

    --
    Derk Gwen http://derkgwen.250free.com/html/index.html
    But I do believe in this.
     
    Derk Gwen, Jun 26, 2003
    #1
    1. Advertising

  2. Derk Gwen

    Zoran Cutura Guest

    Derk Gwen <> wrote:
    > Christopher Culver <> wrote:
    > # I have a string which should include a hexadecimal number. I've tried %x
    > # like this:
    > #
    > # 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?
    >
    > %04x


    That will be missing the leading 0x part. Either add it manually to the
    above or use %#04x instead.
    --
    Z ()
    "LISP is worth learning for the profound enlightenment experience
    you will have when you finally get it; that experience will make you
    a better programmer for the rest of your days." -- Eric S. Raymond
     
    Zoran Cutura, Jun 26, 2003
    #2
    1. Advertising

  3. Zoran Cutura <> wrote (26 Jun 2003) in
    news:bde0vo$ntq$-felb.debis.de / comp.lang.c:

    > Derk Gwen <> wrote:
    >> Christopher Culver <>
    >> wrote: # I have a string which should include a hexadecimal number.
    >> I've tried %x # like this:
    >> #
    >> # 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?
    >>
    >> %04x

    >
    > That will be missing the leading 0x part. Either add it manually to
    > the above or use %#04x instead.


    I think you mean %#06x. Count the characters: 0x007e


    --
    Martin Ambuhl
    Returning soon to the
    Fourth Largest City in America
     
    Martin Ambuhl, Jun 26, 2003
    #3
  4. Derk Gwen

    Zoran Cutura Guest

    Martin Ambuhl <> wrote:
    > Zoran Cutura <> wrote (26 Jun 2003) in
    > news:bde0vo$ntq$-felb.debis.de / comp.lang.c:
    >
    >> Derk Gwen <> wrote:
    >>> Christopher Culver <>
    >>> wrote: # I have a string which should include a hexadecimal number.
    >>> I've tried %x # like this:
    >>> #
    >>> # 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?
    >>>
    >>> %04x

    >>
    >> That will be missing the leading 0x part. Either add it manually to
    >> the above or use %#04x instead.

    >
    > I think you mean %#06x. Count the characters: 0x007e


    Yes I meant 6 not 4 (which I cut'n'pasted fro the original posting).

    I think my brain needs a fart update. I'm producing to much waste in the
    past.

    --
    Z ()
    "LISP is worth learning for the profound enlightenment experience
    you will have when you finally get it; that experience will make you
    a better programmer for the rest of your days." -- Eric S. Raymond
     
    Zoran Cutura, Jun 26, 2003
    #4
    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. Martin Ambuhl
    Replies:
    1
    Views:
    839
    Dan Pop
    Jun 26, 2003
  2. bd
    Replies:
    0
    Views:
    682
  3. Replies:
    15
    Views:
    12,020
    Eric Sosman
    Jun 23, 2006
  4. tobleron
    Replies:
    9
    Views:
    12,746
    Martin Gregorie
    Oct 27, 2008
  5. Randy Kramer
    Replies:
    12
    Views:
    383
    Robert Klemme
    Oct 25, 2007
Loading...

Share This Page