CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

%Modules operator

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
tong
Guest







%Modules operator
PostPosted: Mon Dec 11, 2006 3:06 am     Reply with quote

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
PostPosted: Mon Dec 11, 2006 3:19 am     Reply with quote

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







PostPosted: Mon Dec 11, 2006 3:30 am     Reply with quote

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







PostPosted: Mon Dec 11, 2006 6:19 pm     Reply with quote

HI ThTtelmah

%U is OK ,That's right. Thank you.
Thanks for your help.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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