Hi, Everybody, Is there anyone have the same problems while using %x as the output type for sprintf()? The outputs have the following sequences... 0 1 2 3 4 5 6 7 8 9 @ a b c d e But it should be... 0 1 2 3 4 5 6 7 8 9 a b c d e f Codes:
for(i=0;i<16;i++) { sprintf(Buf,"%x",(int)i);//%X has the same problem. }
Thanks for all of your kindly reply. Please see the example again...
#pragma disable void my_puts (void *p) { unsigned char *pb=(unsigned char *)p; while(*pb) { TI=0; SBUF0=*pb; ++pb; while(!TI); } } void test (void) { char xdata BufA[30]; int x=0xABC;//2748. sprintf(BufA,"0xABC:%x,%X,%u:0xabc\r",x,x,x); my_puts(BufA); sprintf(BufA,"%d,%d,%d,%x\r",(int)(x>>8),(int)(x>>4&0xF),(int)(x&0xF),x); my_puts(BufA); for(;;); }
I think you need to post the smallest complete, compilable program that exhibits the problem.