Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: How to show a string with hexadecimal integer included?

Reply
Thread Tools

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

 
 
Martin Ambuhl
Guest
Posts: n/a
 
      06-26-2003
Christopher Culver <> wrote
(25 Jun 2003) in news: s.com
/ 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
 
Reply With Quote
 
 
 
 
Dan Pop
Guest
Posts: n/a
 
      06-26-2003
In <Xns93A5C8668263mambuhlearthlinknet@207.217.77.2 6> Martin Ambuhl <> writes:

>Christopher Culver <> wrote
>(25 Jun 2003) in news: s.com
>/ 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:
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Change a string to an integer, report an error if the string does not represent an integer? Randy Kramer Ruby 12 10-25-2007 09:56 PM
Converting negative integer to octal/hexadecimal jaks.maths@gmail.com C Programming 15 06-23-2006 12:06 PM
Re: How to show a string with hexadecimal integer included? bd C Programming 0 06-26-2003 05:10 PM
Re: How to show a string with hexadecimal integer included? Derk Gwen C Programming 3 06-26-2003 11:03 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57