View previous topic :: View next topic |
Author |
Message |
Chen Guest
|
printf can handle only two hex digits? |
Posted: Fri Feb 07, 2003 9:28 am |
|
|
unsigned int16 i=0x5678;
char string [20];
byte stringptr=0;
tostring(char c){
if (c=='\f')
stringptr=0;
else
string[stringptr++]=c;
string[stringptr]=0;
}
....
printf(tostring, "\f\%4X", i);
----> string = "0078" instead of "5678"!
___________________________
This message was ported from CCS's old forum
Original Post ID: 11388 |
|
|
Hans Wedemeyer Guest
|
Re: printf can handle only two hex digits? |
Posted: Fri Feb 07, 2003 9:48 am |
|
|
You need to tell printf()it is a long..
like this
:=unsigned int16 i=0x5678;
:=printf(tostring, "\f\%4LX", i);
___________________________
This message was ported from CCS's old forum
Original Post ID: 11390 |
|
|
Chen Guest
|
wow, |
Posted: Fri Feb 07, 2003 10:16 am |
|
|
a 16-bit integer is already a long!
Thanks
:=You need to tell printf()it is a long..
:=like this
:=
:=:=unsigned int16 i=0x5678;
:=:=printf(tostring, "\f\%4LX", i);
___________________________
This message was ported from CCS's old forum
Original Post ID: 11393 |
|
|
R.J.Hamlett Guest
|
Re: wow, |
Posted: Fri Feb 07, 2003 10:50 am |
|
|
:=a 16-bit integer is already a long!
:=
:=Thanks
Yes, but _printf_ is designed to accept the default short integer by standard. If you are passing it a long, it requires the 'L' format (this works for both 16bit and 32bit 'longs).
Best Wishes
:=:=You need to tell printf()it is a long..
:=:=like this
:=:=
:=:=:=unsigned int16 i=0x5678;
:=:=:=printf(tostring, "\f\%4LX", i);
___________________________
This message was ported from CCS's old forum
Original Post ID: 11394 |
|
|
Sherpa Doug Guest
|
Re: wow, |
Posted: Fri Feb 07, 2003 11:27 am |
|
|
:=a 16-bit integer is already a long!
:=
:=Thanks
:=
Check out the definition of a short.
;-)
___________________________
This message was ported from CCS's old forum
Original Post ID: 11397 |
|
|
|