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

XOR byte operator

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







XOR byte operator
PostPosted: Fri Oct 08, 2004 9:00 am     Reply with quote

Does anyone know what the byte operator is for a XOR operation?

Regards,

Darren
Code:
Ttelmah
Guest







Re: XOR byte operator
PostPosted: Fri Oct 08, 2004 9:19 am     Reply with quote

guest wrote:
Does anyone know what the byte operator is for a XOR operation?

Regards,

Darren
Code:


^

Best Wishes
guest
Guest







PostPosted: Fri Oct 08, 2004 9:33 am     Reply with quote

Isn't that a bit-wise operator. I want to XOR two bytes together as a basic checksum.

i.e.
Code:

      01011011
XOR   10011001
--------------
      11000010


Any other thoughts?

Thanks

Darren.
Ttelmah
Guest







PostPosted: Fri Oct 08, 2004 10:32 am     Reply with quote

guest wrote:
Isn't that a bit-wise operator. I want to XOR two bytes together as a basic checksum.

i.e.
Code:

      01011011
XOR   10011001
--------------
      11000010


Any other thoughts?

Thanks

Darren.

That is what the operator does. an XOR of each bit in the byte with the corresponding bit in the other byte. It is 'bitwise', because it does this, rather than treating the whole byte as a 'logical' entity.

Best Wishes
jamesjl



Joined: 22 Sep 2003
Posts: 52
Location: UK

View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger

PostPosted: Fri Oct 08, 2004 10:49 am     Reply with quote

Great,

Thanks for the help.
Squintz



Joined: 08 Dec 2009
Posts: 11

View user's profile Send private message

PostPosted: Fri Jan 15, 2010 1:43 pm     Reply with quote

Sorry to bring up such an old thread. Newbie Here!

Is it valid to XOR two inputs to determine an output? Below is what I am trying to do. Basically I want to compare a Switch to an LED and if they are different I want to toggle an output. For some reason I never see the output go High. It constantly stays low. What am I doing wrong?

Code:

#include <12F675.h>

#fuses INTRC_IO     //Inernal RC Oscillator
#fuses NOWDT        //No Watchdog Timer
#fuses NOBROWNOUT   //No Brownout Detection
#fuses NOMCLR       //No Master Clear Reset. Used for I/O Instead

#use delay(clock=31000) //

void main(void)
{
   while(1)
   {
      // if the Switch and the LED are opposite then toggle the power
      if(input(PIN_A3)^input(PIN_A2))       // XOR Switch to LED
      {
         //Turn the unit on
          output_low(PIN_A5);                 // Simulate power button press         
            delay_ms(500);                  // Wait with button pressed...
            output_float(PIN_A5);            // Simulate power button release
      }else{
         output_float(PIN_A5);
      }

      delay_ms(200);                         // Wait before checking again.
   }
}
Rohit de Sa



Joined: 09 Nov 2007
Posts: 282
Location: India

View user's profile Send private message Visit poster's website

PostPosted: Fri Jan 15, 2010 2:37 pm     Reply with quote

^ is a bitwise operator, not a logical operator.
You could always try:
Code:
int1 a=0;
int1 b=0;
int1 c=0;


Code:
a=input(pin_a3);
b=input(pin_a2);
c=((!a)&&b)||(a&&(!b));

if(c)
.
.
.


Rohit
Squintz



Joined: 08 Dec 2009
Posts: 11

View user's profile Send private message

PostPosted: Fri Jan 15, 2010 3:19 pm     Reply with quote

I actually got it to work pretty much exactly how it is but I changed output_float to output_high. It was executing the code I just was not seeing it on my oscope because float essentially disconnect the output pin. I thought float was the same as high but I guess I was wrong.

Thanks for the alternative solution.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Fri Jan 15, 2010 3:43 pm     Reply with quote

Quote:
^ is a bitwise operator, not a logical operator.
Applying ^ to int1 respectively bit variables achieves a "logical" XOR. In so far, bitwise operator function
includes the logical. Applying a logical operator to variables larger than one bit performs an implicite (var !=0)
before the logical operation.

There have been however issues, at least with CCS V3, where bits in structures have been erroneously
bitwise processed in logical operations.

In the present case, using ^saves a few machine instructions, although the generated code is very similar to
the suggested more long-winded construction.
Code:
if(input(PIN_A3)^input(PIN_A2))
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