ooPIC Logo

Bitwise and Logical Operators

Main Index
Language Idx
Back to top of pageDescription:
 Operators are used to compare two values in various ways.

1: An Operator that performs a bitwise conjunction on the surrounding expressions.
2: An Operator that performs a logical conjunction on the surrounding expressions. 

For Bitwise Operators, the ooPIC performs a bitwise comparison of identically positioned bits in two numeric expressions and sets the corresponding bit in the result according to the logic specified by the operator. 

For Logical Operators, the ooPIC uses bit 1 exclusively to determine if a value is true or false and therefore, makes no distinction between a logical operator used in an if/then statement and a bitwise operator used to modify a variable. Both bitwise and logical applications will expect the same syntax and operate in a similar manner.  In firmware version B3, Local operators &&, II and ! were added to the C syntax which considers any value other than zero to have bit 1 set.  See Version history for more detail.

Back to top of pageSyntax:
 The following shows the format of the Bitwise/Logical Operator syntax.
 Basic Bitwise/LogicalC & Java BitwiseC & Java Logical
And<exp1> And <exp2><exp1> & <exp2><exp1> && <exp2>
Or<exp1> Or <exp2><exp1> | <exp2><exp1> || <exp2>
XOR<exp1> XOR <exp2><exp1> ^ <exp2> 
NotNot <exp1>~ <exp1>! <exp1>

The following table lists the elements of the Bitwise/Logical Operator syntax.
ElementDescription
<exp1>Any valid exp.
<exp2>Any valid exp.

Back to top of pageOperation:
 Logical And evaluates as follows: If, and only if, both expressions evaluate to cvTrue, the result is cvTrue. If either exp evaluates to cvFalse, the result is cvFalse.

Bitwise And performs a bitwise evaluation of identically positioned bits in two numeric expressions and writes the corresponding bit in the result.

The following table illustrates how the results are determined:

<Exp1>

<Exp2>

Evaluation

False

False

False

True

False

False

False

True

False

True

True

True

Logical Or evaluates as follows: If, either of the expressions evaluate to cvTrue, the result is cvTrue.

Bitwise Or operator also performs a bitwise evaluation of identically positioned bits in two numeric expressions and writes the corresponding bit in the result.

The following table illustrates how result is determined:

<Exp1>

<Exp2>

Evaluation

False

False

False

True

False

True

False

True

True

True

True

True

Logical XOR evaluates as follows: If, either of the expressions evaluate to cvTrue, but not both, the result is cvTrue.

Bitwise XOR operator also performs a bitwise evaluation of identically positioned bits in two numeric expressions and writes the corresponding bit in the result.

The following table illustrates how result is determined:

<Exp1>

<Exp2>

Evaluation

False

False

False

True

False

True

False

True

True

True

True

False

Logical Not inverts the evaluation of the expressions.

Bitwise Not operator also performs a bitwise invert of bits in <exp1> and writes the corresponding bit in the result.

The following table illustrates how result is determined:

<Exp1>

Evaluation

False

True

True

False

Back to top of pageRemarks:
 Logical Operators can also be done with the oMath Object.
Back to top of pageExample:
 The following are simple uses for logical and bitwise operators.
Visual Basic Syntax C and Java Syntax
'Logical operator
If (A>0) And (A<45) Then
 '<statements>
End If
'Bitwise operation
A = B And C
//Logical operator
If ((A>0) && (A<45)) {
 //<statements>
}
//Bitwise operation
A = B & C;
Basic Syntax
'Logical operator
If (A>0) And (A<45) Then '<statements>
'Bitwise operation
A = B And C

Back to top of pageRelated Items:

 Arithmetic Operators

Relational Operators

Back to top of pageVersion History and Bug List:
 Firmware Ver A1: Introduced: Bitwise Operators And, Or, Not & Xor.
Firmware Ver A1: Notes: Local operations were handled by evaluating bit 1 exclusively and therefore Bitwise Operators were used for both Bitwise and Logical operations.

Firmware Ver B3: Added: Logical Operators for &&, || and !
Firmware Ver B3: Notes: Local operations are still handled by evaluating bit 1 exclusively and therefore either Bitwise Operators or Logical Operators can be used for logical operations.  However, the new Logical Operators will consider any value other than 0 to have bit 1 set when evaluated.

Compiler Ver 6: Added: Logical Operators &&, ||, ! to the C syntax to support the additions in Firmware B3.

Bugs: No known bugs.


ooPIC Compiler Ver 6.0 (c) Copyright 1997 - 2007 Savage Innovations, LLC.