|
|
View previous topic :: View next topic |
Author |
Message |
tong Guest
|
%Modules operator |
Posted: Mon Dec 11, 2006 3:06 am |
|
|
problem %Modules operator.
I'm using PCM 3.249 version.
void main(void){
long a;
char b,c;
c=6789;
b=(char)(a/256); //--->26=hex1A
c=(char) (a%256); //---->133=hex85
printf(lcd_putc,"\f %d%d",b,c); //b=26 OK c= -123 (133 is ok)
//why c is -123 ?
} |
|
|
tong Guest
|
sorry a=5678 |
Posted: Mon Dec 11, 2006 3:19 am |
|
|
tong wrote: | problem %Modules operator.
I'm using PCM 3.249 version.
void main(void){
long a;
char b,c;
a=6789; //sorry
b=(char)(a/256); //--->26=hex1A
c=(char) (a%256); //---->133=hex85
printf(lcd_putc,"\f %d%d",b,c); //b=26 OK c= -123 (133 is ok)
//why c is -123 ?
} |
|
|
|
Ttelmah Guest
|
|
Posted: Mon Dec 11, 2006 3:30 am |
|
|
Because you are using the wrong printf declaration.
%d, prints a _signed_ number. %u, prints an 'unsigned'. Now, '133', in binary is 1000 0101. Signed numbers use the first bit as a flag to say this is a -ve number. So when you print this binary value using %d, it is printed as -123.
Print using %u, and everything will be OK.
Best Wishes |
|
|
tong Guest
|
|
Posted: Mon Dec 11, 2006 6:19 pm |
|
|
HI ThTtelmah
%U is OK ,That's right. Thank you.
Thanks for your help. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|