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

And operation

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



Joined: 05 Sep 2007
Posts: 252

View user's profile Send private message

And operation
PostPosted: Mon Jul 14, 2008 6:30 am     Reply with quote

Hi Everyone;
how can i use and operation
suppose i want to and two values
value1=0x11110000;
&
value2=0x00001010;

and store the result in value3.

i tried it but not successful
my code is like that
Code:

void main ()
{
int8 value1,value2,value3;
value1=0x11110000;
value2=0x00001010;
value3=(value1 && value2);
printf("%2x\r\n",value3);
}

but i am not getting the actual value after and operation.
what is wrong in my code.
i know its a basic question
thiru_electrifiers



Joined: 05 Jul 2008
Posts: 3

View user's profile Send private message

wrong syntax
PostPosted: Mon Jul 14, 2008 7:35 am     Reply with quote

hi,
in your expression,
Code:
value3=(value1 && value2);

do not use double &.
use like this
Code:
value3=(value1 & value2);
rberek



Joined: 10 Jan 2005
Posts: 207
Location: Ottawa, Canada

View user's profile Send private message

PostPosted: Mon Jul 14, 2008 7:36 am     Reply with quote

Use a single "&" and don't use "&&"

"&&" does an AND comparison. The single "&" is for the mathematical operation.

r.b.
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Mon Jul 14, 2008 8:30 am     Reply with quote

Quote:
int8 value1,value2,value3;
value1=0x11110000;
value2=0x00001010;
value3=(value1 && value2);


You have declared value1, value2 & value3 as 8-bit variables yet you are assigning a 4-BYTE value to them. 0x11110000 indicates a HEX value. If you want to assign an 8-bit value then use 0b11110000. This will greatly affect your program.

Ronald
hayee



Joined: 05 Sep 2007
Posts: 252

View user's profile Send private message

PostPosted: Tue Jul 15, 2008 5:53 am     Reply with quote

Thanks all of u
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