958 |
<h3>Boolean Operators</h3> |
<h3>Boolean Operators</h3> |
959 |
<p> |
<p> |
960 |
To perform logical transformations of <i>boolean</i> data, you may use the |
To perform logical transformations of <i>boolean</i> data, you may use the |
961 |
following boolean operators: |
following logical operators: |
962 |
</p> |
</p> |
963 |
<code> |
<code> |
964 |
on init |
on init |
971 |
end on |
end on |
972 |
</code> |
</code> |
973 |
<p> |
<p> |
974 |
Remember that with boolean operations, all integer values other than <code>0</code> |
Keep in mind that with logical operators shown above, |
975 |
|
all integer values other than <code>0</code> |
976 |
are interpreted as boolean <i>true</i> while an integer value of |
are interpreted as boolean <i>true</i> while an integer value of |
977 |
precisely <code>0</code> is interpreted of being boolean <i>false</i>. |
precisely <code>0</code> is interpreted of being boolean <i>false</i>. |
978 |
</p> |
</p> |
979 |
|
<p> |
980 |
|
So the logical operators shown above always look at numbers at a whole. |
981 |
|
Sometimes however you might rather need to process numbers bit by bit. For |
982 |
|
that purpose the following bitwise operators exist. |
983 |
|
</p> |
984 |
|
<code> |
985 |
|
on init |
986 |
|
message("1 .and. 1 is " & 1 .and. 1) { bitwise "and" } |
987 |
|
message("1 .and. 0 is " & 1 .and. 0) { bitwise "and" } |
988 |
|
message("1 .or. 1 is " & 1 .or. 1) { bitwise "or" } |
989 |
|
message("1 .or. 0 is " & 1 .or. 0) { bitwise "or" } |
990 |
|
message(".not. 1 is " & .not. 1) { bitwise "not" } |
991 |
|
message(".not. 0 is " & .not. 0) { bitwise "not" } |
992 |
|
end on |
993 |
|
</code> |
994 |
|
<p> |
995 |
|
Bitwise operators work essentially like logical operators, with the |
996 |
|
difference that bitwise operators compare each bit independently. |
997 |
|
So a bitwise <code>.and.</code> operator for instance takes the 1st bit |
998 |
|
of the left hand's side value, the 1st bit of the right hand's side value, |
999 |
|
compares the two bits logically and then stores that result as 1st bit of |
1000 |
|
the final result value, then it takes the 2nd bit of the left hand's side value |
1001 |
|
and the 2nd bit of the right hand's side value, compares those two bits logically |
1002 |
|
and then stores that result as 2nd bit of the final result value, and so on. |
1003 |
|
</p> |
1004 |
|
|
1005 |
|
|
1006 |
<h3>Comparison Operators</h3> |
<h3>Comparison Operators</h3> |
1007 |
<p> |
<p> |