0

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

null
    • smason
    • 3 wk ago
    • Reported - view

    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.

      • damon_vinciguerra.1
      • 3 wk ago
      • Reported - view

      Thanks  And just to clarify, the difference between && and & is that with &, it will check all expressions where as && will start from the left and as soon as something is true it will stop checking and output true?

      • smason
      • 3 wk ago
      • Reported - view

      Not really. && compares two logical statements and if they are both true, it returns true. & compares the individual bits of two values. In the diagram above, it is comparing the bits of two numbers, 21 (10101) and 28 (11100). For each column where both are 1, the & function returns 1. In this case it returns 10100 which is the binary representation of 20. So 21 & 28 = 20.

      • damon_vinciguerra.1
      • 3 wk ago
      • Reported - view

      Whoa, that is absolutely a bonkers application. Note to self: stay away from &. Thanks!

Content aside

print this pagePrint this page
  • 3 wk agoLast active
  • 4Replies
  • 13Views
  • 2 Following