char str [4];
sprintf (str, "%.2x", 0x01);//Conversion of byte to the 2nd bit hexadecimal value
I expect in str[0] 0 character, in str[1] 1 character, that is '0' and '1'. As a result function returns '1' and 'C'. Remaining numbers - it is normal...
I appreciate your "Total and absolute rubbish". Well, I have it tested, confirmed the problem in the first place, and the fix using 16bit. Beside that, the problem is also visible using just a simple "%x" format sting. And I do really assume that YOU have also reproduced and tested your fix, don't you? I will not use inappropiate wording in my response, sorry.
You might also carefully read
http://www.keil.com/support/man/docs/c51/c51_printf.htm
and there understand the difference between %bx and %x, another option to solve the primary problem:
printf ("xchar %bx xint %x xlong %lx\n",x,y,z);
Got it? Reading helps!
Oh dear. Why post a link to a page that you've clearly not fully comprehended?
Nice to see active discussion.
As an arbitrator I will say that both of you are right. The (unsigned int) is there to ensure a 16 bit value is passed as a parameter and the 2.2X to ensure the resultant string consists of two hex characters. There are likely many ways to do it, but the combination works for me. In the same way that any of the C51 workarounds for the weird architecture ever made sense.
IMHO, the sooner the x51 is taken out of college teaching the better.