arduino implementation of digital expression

how should i write this statement in c language for arduino?

a= [NOT(b) OR (c)]

variables a,b and c will be used to hold a single bit each,
ie- either a '1' or a '0'.

i know its one of the silliest query you may ever come across but please help... :frowning:

Depends if those are logical or bitwise operations.

Shivarungta,

this isn't a silly question at all, it has a few pitfalls for the unwary.

If you consider your variables boolean, which in C means 0 is false and not 0 is true (usually the value 1 is used, but any other value will do) you'd do:

a = (c || ! b);

Note the parentheses after the = are very important, otherwise you will assign c to a and the result of the expression itself won't be assigned. Also note, the boolean or || is used.

On the other hand, if you want to do bitwise operation on the first bit only, you'd use:

a = (c | ~b) & 1;

The bitwise and & 1 at the end makes sure, that only the result of the last bit is returned and all other bits are set to zero. Note also, that the bitwise or | is used here.

If b and c contain only 0 and 1, the results will be the same. However if you have b = 1 and c =2, the first expression returns true (1), the second returns 0 because only the last bit is taken into consideration.

I hope that clear up things a little.

Korman

thanks a lot KORMAN !! :smiley: ............ i really appreciate your help!!

and AWOL...thanx to you as well...... :slight_smile:

KORMAN, can u please help solve my problem posted as another topic? i would really appreciate it!! :slight_smile: