Bitwise vs Logical operators

From Flowcode Help
Revision as of 16:31, 14 December 2023 by MartinW (talk | contribs) (Created page with "Logical operators compare two expressions and return 'true' or 'false' as a result. For example: result = (x == 3) && (y == 4) //result will be true only if x equals 3 and...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Logical operators compare two expressions and return 'true' or 'false' as a result. For example:

 result = (x == 3) && (y == 4)  //result will be true only if x equals 3 and y equals 4
 my_value = !my_value           //toggle the BOOL var (e.g. if it is false, it becomes true)

Bitwise operators take two numbers and then compare the bits of each number, resulting in a new number. They are often used to set or clear individual bits in a value or register, or to mask off some bits from a value. Some examples are:

 result = val & 0x0F     //mask off the lowest 4 bits (e.g. if val is 0x45, result will be 0x05)
 my_val = my_val | 0x01  //ensure the lowest bit of my_val is set to 1