449,079 Members | 843 Online
Need help? Post your question and get tips & solutions from a community of 449,079 IT Pros & Developers. It's quick & easy.

# %#08x formatting of printf

 P: n/a Hi, I use %#08x to print unsigned integers in hexadecimal format. According to C ref. man. Harbison & Steele, #08 stands for "pad the number with up to 8 zeroes to complete it to 8 digit number". Is this correct understanding? However this is not always the case. I sometimes see 4, sometimes 2, that does not complete the whole number into 8 digits. I don't know what changes this, but do you have an alternative that definitely pads to 8 digits? Thanks, Bahadir Jan 26 '06 #1
5 Replies

 P: n/a Bi*************@gmail.com wrote: Hi, I use %#08x to print unsigned integers in hexadecimal format. According to C ref. man. Harbison & Steele, #08 stands for "pad the number with up to 8 zeroes to complete it to 8 digit number". Is this correct understanding? However this is not always the case. I sometimes see 4, sometimes 2, that does not complete the whole number into 8 digits. I don't know what changes this, but do you have an alternative that definitely pads to 8 digits? Thanks, Bahadir The # is a flag prefixing "0x" to the result The 8 is the minimum field width (but some of the field may consist of spaces before the "0x"). You really need a precision of 8 and a field width of 10 (to include the "0x", so you need: "%#10.8x" Robert Jan 26 '06 #2

 P: n/a No time to check, but as I recall I used something like printf("%08x", ....) or printf("0x%08", ...) for the prefix. I never used the # tag. -- Henryk Jan 26 '06 #3

 P: n/a On 2006-01-26, Henryk wrote: No time to check, but as I recall I used something like printf("%08x", ....) or printf("0x%08", ...) for the prefix. I never used the # tag. That's because the # tag doesn't apply to a value of zero. Jan 26 '06 #4

 P: n/a Robert Harris wrote: The # is a flag prefixing "0x" to the result The 8 is the minimum field width (but some of the field may consist of spaces before the "0x"). You really need a precision of 8 and a field width of 10 (to include the "0x", so you need: "%#10.8x" Robert Thanks, I'll try this. Bahadir Jan 26 '06 #5