View previous topic :: View next topic |
Author |
Message |
hayee
Joined: 05 Sep 2007 Posts: 252
|
And operation |
Posted: Mon Jul 14, 2008 6:30 am |
|
|
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
|
wrong syntax |
Posted: Mon Jul 14, 2008 7:35 am |
|
|
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
|
|
Posted: Mon Jul 14, 2008 7:36 am |
|
|
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
|
|
Posted: Mon Jul 14, 2008 8:30 am |
|
|
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
|
|
Posted: Tue Jul 15, 2008 5:53 am |
|
|
Thanks all of u |
|
|
|