CanaryAnd, and, &&, &
As far as I can tell, there are at least 4 ways to do an AND operation in Calculation: CanaryAnd, and, &&, &. Similarly for OR (CanaryOr, or, ||, |). And not equal has != and <>. Are there any functional differences in these options? Or is it just up to preference. The only option of the 4 I can find any info on is CanaryAnd.
Also, what do <<, >> and ~ do?
4 replies
-
Hi ,
&& and "and" are interchangeable. CanaryAnd has the same functionality, but you can pass in multiple items as an array. For example, these three expressions are equivalent:
[Tag1]>1 and [Tag2]=10 and [Tag3]<5
[Tag1]>1 && [Tag2]=10 && [Tag3]<5
CanaryAnd([Tag1]>1, [Tag2]=10, [Tag3]<5)
The same goes for the "or"s.
& and | are bitwise operations where you are comparing the bits of the values. Here is a diagram illustrating a bitwise "and", "or", and "exclusive or" between two numbers.
Both bits have to equal 1 for the "and" to return 1. At least one bit has to equal 1 for the "or" to return 1. Exactly 1 bit has to equal 1 for the "exclusive or" to return 1. We use ^ for "exclusive or".
!= and <> are interchangeable.
~, <<, and >> are also bitwise functions. ~ inverts the bits of a value. << and >> shift the bits left and right. See https://stackoverflow.com/questions/141525/what-are-bitwise-shift-bit-shift-operators-and-how-do-they-work for more details.