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...
All thanks for discussion. Works correctly: sprintf (str, "%.2x", (unsigned int)0x01) sprintf (str, "%2.2x", (unsigned int)0x01) There is a question. Why in Embarcadero® C++Builder 10.1 Berlin transformation of types isn't required.
And yes. MCS51 shouldn't offend. :) Similar it is just such realization of the sprintf function in the environment of KEIL.
There is a question. Why in Embarcadero® C++Builder 10.1 Berlin transformation of types isn't required.
A better question is: Why does C51 require it?
The C51 compiler does an extremely good job of making C and its libraries available to a processor that is not really suitable for such things. It requires a number of extensions to make best use of the limited resources of the old processors.
But things have really moved on since the 1990s (I was an original tester of quite a few C51 releases back in those days). Many processors (such as ones having an ARM Cortex core) don't require these extensions and 'just work'.
My suggestion to you is move across to the currently available processors and technologies as soon as you can. You'll find things a whole lot easier :)
But in case of what here processor type? It is feature of implementation of function in the environment of KEIL, only...