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 Version History

« Previous Version 13 Next »

There are three types of operators that can be used in programs:

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

Variable A and B are added. The result is 7.

-

Subtraction

A - B

Variable B is subtracted from A. The result is -1.

*

Multiplication

A * B

Variable A and B are multiplied. The result is 12.

/

Division

A / B

Variable A is divided by 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.

Logical/Comparative Operator

In the table shown below, the calculation result assumes that variable A is 1 (True) and variable B is 0 (False). In Canvas, 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 value in variables A and B are true, the result is 1. In other cases, the result is 0.

||

Logical OR

A || B

If value in variables A or B are true, the result is 1. In other cases, the result is 0.

Less than

A < B

If A is less 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 equal to B, the result is 1. In other cases, the result is 0.

Other Operator

Operator

Function

Example

Description

=

Store

A = B

Stores the value in variable B to variable 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 the operator will be treated as the result value of the = operation. The example mentioned above will be processed internally in the program as shown below:

B C

A B

 


 

  • No labels