printf("%#02bx",0xff); The above line of code does what I'd expect, ie it prints out "0xff". However, printf("%#02bx",0x00); prints out "0x000000000000000"..... for a very long time. The same happens for any value between 0x00 and 0x0f, 0x10 to 0xff work as expected. Is this a bug or am I being stupid? I'm using C51 V7.
What about to try:
printf("%#04x",0x00);
What about to try: printf("%#04x",0x00); Yes, this works, but doesn't explain why printf("%#02x",0x00); or printf("%#02bx",0x00); doesn't. This problem seems to occur only when the minimum field width specifier is two and the data is in the range 0x00 to 0x0f. Could someone confirm whether this is a bug in printf() by compiling and running that line of code?
I checked that with C166, same result: a long tail of zeros. Seems like the source code (including bugs) for printf is the same for C51 and C166. - Mike
I've tried it on C51 v6.23a and Borland C++ Builder v5. Borland is fine, but C51 behaves as you describe. I wonder if it's because you have specified the field width as 2, but also specified that "0x" is to be added - presumably you actually want a field width of 4, to hold "0xnn"?
View all questions in Keil forum