在C51中,使用printf()函数进行格式化输出时,格式控制符与ANSI C有所不同。
在格式控制字符中,b表示byte
以十进制输出uint8_t : %bu
以十进制输出int8_t : %bd
#include <stdio.h> void tst_printf (void) { char a = 1; int b = 12365; long c = 0x7FFFFFFF; unsigned char x = 'A'; unsigned int y = 54321; unsigned long z = 0x4A6F6E00; float f = 10.0; float g = 22.95; char buf [] = "Test String"; char *p = buf; printf ("char %bd int %d long %ld\n",a,b,c); printf ("Uchar %bu Uint %u Ulong %lu\n",x,y,z); printf ("xchar %bx xint %x xlong %lx\n",x,y,z); printf ("String %s is at address %p\n",buf,p); printf ("%f != %g\n", f, g); printf ("%*f != %*g\n", (int)8, f, (int)8, g); }