Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

There are three types of operators that can be used in the programs: Calculation Operator, Logical/Comparative Operator and Others.

(1) Calculation Operator

In the table below, the calculation result assumes variable A is 3 (0000 0000 0000 0011), and the variable B is 4 (0000 0000 0000 0100).

Remainder calculation and all Bitwise calculations will be performed with 32-bit integer data.

Operator

Function

Example

Description

~

Bitwise invert

~A

Each bit of A (0000 0000 0000 0011b) is inverted. The result is 1111 1111 1111 1100b.

+

Addition

A+B

Adds A and B. The result is 7.

-

Subtraction

A –B

Subtracts B from A. The result is -1.

*

Multiplication

A*B

Multiplies A and B. The result is 12.

/

Division

A / B

Divides A with B. The result is 0.75.

%

Remainder

A % B

Indicates the remainder from the division of A with B. The result is 3.

&

Bitwise AND

A & B

Bitwise logical AND calculation of A and B. The result is 0.

|

Bitwise OR

A | B

Bitwise logical OR calculation of A and B. The result is 0111b (= 7).

^

Bitwise XOR

A ^ B

Bitwise logical XOR calculation of A and B. The result is 0111b (= 7).

<< 

Bitwise Shift Left

A << B

Shifts the bits of A to the left as much as B. The rightmost part is filled with 0. The result is 0011 0000b (= 48).

>> 

Bitwise Shift Right

A >> B

Shifts the bits of A to the right as much as B. The leftmost part is filled with 0. The result is 0.

(2) Logical/Comparative Operator

In the table shown below, the calculation result assumes that the variable A is 1 (True) and the variable B is 0 (False). In Xpanel, the values other than 0 are all processed as True. Only 0 is recognized as False.

When the calculation result is true, the result is always 1.

Operator

Function

Example

Description

&&

Logical AND

A && B

If A and B are true, the result is 1. In other cases, the result is 0.

||

Logical OR

A || B

If A and B are false, the result is 0. In other cases, the result is 1.

Less than

A < B

If A is smaller than B, the result is 1. In other cases, the result is 0.

Greater than

A > B

If A is greater than B, the result is 1. In other cases, the result is 0.

<= or =<

Less than or equal to

A <= B

If A is smaller than or equal to B, the result is 1. In other cases, the result is 0.

>= or =>

Greater than or equal to

A >= B

If A is greater than or equal to B, the result is 1. In other cases, the result is 0.

==

Equal to

A == B

If A is equal to B, the result is 1. In other cases, the result is 0.

!=

Is not equal to

A != B

If A is not B, the result is 1. In other cases, the result is 0.

(3) Other Operator

Operator

Function

Example

Description

=

Store

A = B

Stores the value B to A and uses it as a result.

The Store (=) operator can be used consecutively.

A = B = C;

In this case, the value of A and B will be set as C. In other words, the value at the rightmost side of operator will be treated as the result value of “=” operation. The example mentioned above will be processed internally in the program as shown below.

B ← C

A ← B

 

(blue star)

The features of the “=” operator may cause a program error that cannot be detected as shown below. Even if the values of A and B are not equal, the operation result of the IF statement can be True. This operation may cause an unwanted B value to be stored in A.

 

//===================

// A Program Error That Cannot Be Detected

//===================

If (A=B) // Mis-entry of A==B, checking if the value of A and B are same.

{

}

 


 

  • No labels