Logic

Logic functions provide Boolean algebra and conditional testing capabilities to the In-Sight spreadsheet. All bitwise functions perform the corresponding logical operation on each bit position in the binary representation of the arguments and return the resulting binary number in decimal form.  For example, bit 0 of Value0 is compared to bit 0 of Value1, bit 1 of Value0 is compared to bit 1 of Value1, etc.  Bitwise functions are particularly useful with MultiStatus and Discrete I/O Functions, when combining the results of multiple true/false conditions into a GUI display or discrete output. For more information, see MultiStatus or Discrete I/O Functions.

Operator Symbol
NOT !
AND &&
OR ||
Equivalent to ==
Not equal to <> (or !=)
Note:
  • When certain snippets are inserted into the spreadsheet, the formula that appears in the Job Edit Toolbar may contain characters such as !, &&, ||, ==, <>, >=, <=, and !=.

  • The AND and && operators will function differently if an empty cell or a cell containing a string is present in the list of arguments.

For all Logic functions:

  • FALSE = 0
  • TRUE = any non-zero result

Function

Description

And(Value1, Value2, ...)

Returns 1 if all values are non-zero. (Logical AND the result is TRUE when both values are TRUE.)

Note:
  • If arguments reference an empty cell or a cell containing a string, those values are ignored. If all arguments reference empty cells or cells containing strings, the function returns #ERR.

  • The AND and && operators will function differently if an empty cell or a cell containing a string is present in the list of arguments. The AND function ignores cells that are empty or only contain strings, while the && operator does not ignore them. If cell A5 is an empty cell, the function A5&&2 will return 0. If cell A5 contains a string, such as "a", the function A5&&2 will return #ERR.

ClosedExamples

  • And(45, -77) returns 1.
  • And(65534, 0) returns 0.
  • And(-3, -2, -1, 1, 2, 3) returns 1.
  • And(-1, 0, 1) returns 0.

BitAnd(Value1, Value2, ...)

Returns the bitwise AND of values.

Note: Processes only the lower 16 bits.

ClosedExamples

  • BitAnd(45, 77) returns 13.
  • 45 = 0000 0000 0010 1101 in binary.
  • 77 = 0000 0000 0100 1101 in binary.
  • Individually comparing each common bit in these two 16-bit binary numbers using the And operation yields 0000 0000 0000 1101, which = 13 in decimal.

BitNot(Value)

Returns the bitwise inverse of Value.

Note: Processes only the lower 16 bits.

ClosedExamples

  • BitNot(45) returns 65490.
  • 45 = 0000 0000 0010 1101 in binary.  
  • Inverting each 0 to a 1 and each 1 to a 0 yields 1111 1111 1101 0010 in binary, which is 65490 in decimal.

BitOr(Value1, Value2, ...)

Returns the bitwise OR of values.

Note: Processes only the lower 16 bits.

ClosedExamples

  • BitOr(45, 77) returns 109.
  • 45 = 0000 0000 0010 1101 in binary.
  • 77 = 0000 0000 0100 1101 in binary.
  • Individually comparing each common bit in these two 16-bit binary numbers using the Or operation yields 0000 0000 0110 1101, which = 109 in decimal.

BitXor(Value1, Value2, ...)

Returns the bitwise XOR (exclusive OR) of Values. (Logical XOR the result is TRUE if one – and only one – of the bits is TRUE.  The result is FALSE if 2 or more bits are equal.)

Note: Processes only the lower 16 bits.

ClosedExamples

  • BitXor(45, 77) returns 96.
  • 45 = 0000 0000 0010 1101 in binary
  • 77 = 0000 0000 0100 1101 in binary.
  • 0110 0000 are the only non-common bits between 45 and 77, as demonstrated below.
45 77 XOR per bit XOR bit

0

0

two 0s ≥ XOR FALSE

0 (FALSE)

0

1

only one 1 ≥ XOR TRUE

1 (TRUE)

1

0

only one 1 ≥ XOR TRUE

1 (TRUE)

0

0

two 0s ≥ XOR FALSE

0 (FALSE)

1

1

two 1s ≥ XOR FALSE

0 (FALSE)

1

1

two 1s ≥ XOR FALSE

0 (FALSE)

0

0

two 0s ≥ XOR FALSE

0 (FALSE)

1

1

two 0s≥ XOR FALSE

0 (FALSE)

0110 0000 = 96 in decimal.

If(Cond, Value1, Value2)

Returns Value1 if Cond is non-zero; otherwise, returns Value2.

Note: If the condition or the arguments reference empty cells, they are interpreted as a zero (FALSE).

InRange(Value, Start, End)

Returns TRUE if Min(Start,End) ≤ Value ≤ Max(Start,End).

Not(Value)

Returns 0 if Value is non-zero, or 1 if Value is 0. (Logical Inverse)

ClosedExamples

  • Not(-12345) returns 0.
  • Not(3.14) returns 0.
  • Not(2-1) returns 0.
  • Not(1-1) returns 1.

Or(Value1, Value2, ...)

Returns 0 if all values are zero; otherwise, returns 1. (Logical OR the result is TRUE if any of the Values are TRUE.)

ClosedExamples

  • Or(45, -77) returns 1.
  • Or(-1, 0, 1) returns 1.
  • Or(0, 1-1) returns 0.