This command performs a binary comparison of two integers, where each bit of the result is the binary OR of the corresponding bits of the inputs, and then converts this binary result to an integer.
Syntax
number_1 | number_2
Number_1 and number_2 must be integers.
Return value
This command returns a number.
Notes
How Bitor works:
Bitor converts the integers number_1 and number_2 into binary numbers.
It creates a new binary number by placing a 0 in every position where the binary values of number_1 and number_2 both contain a 0, and by placing a 1 in every other position.
Bitor then converts the new binary number to an integer and returns this integer value.
Bitor is a convenient way to sum numeric values while ensuring that each value is only "added" once. For example, it can be used with SETRTCHK to ensure that the value set for this command will be valid.
Alternately, the Bitor can be used to perform multiple logical tests in an IF statement. In the case of more than two conditionals being tested, the conditionals are tested from left to right. Thus, you must use parentheses to control the precedence.
Examples of precedence:
true | false & false = false [this evaluates to (true or false) and false which equals false]
true | (false & false) = true [this evaluates to true or (false and false) which equals true]
Note: When using Bitand or Bitor in the logical_test, use caution with comparative commands, which do not always return 1 for "True" and 0 for "False":
One exception is the Equals symbol (=), which always returns 1 for "True" (numbers are equal) and 0 for "False" (numbers not equal). See Examples below for methods to include comparative commands >, <, and = with Bitand or Bitor in the logical_test. For string comparisons, you can substitute a STRCOMP command for one of the numbers in an Equals (=) comparison, or you can substitute an INSTR command for one of the numbers in a Less than (<) or Greater than (>) comparison. |
Examples
16 | 48
The binary comparison of the integers 16 and 48 looks like this:
|
bit positions of binary number |
||||||
64 |
32 |
16 |
8 |
4 |
2 |
1 |
|
integer 16 = |
0 |
0 |
1 |
0 |
0 |
0 |
0 |
integer 48 = |
0 |
1 |
1 |
0 |
0 |
0 |
0 |
result of '16 | 48' = |
0 |
1 |
1 |
0 |
0 |
0 |
0 |
The Bitor command then converts this new binary value (0110000) to its integer value (48), so this formula returns the number 48.
16 | 32
The binary comparison of the integers 16 and 32 looks like this:
|
bit positions of binary number |
||||||
64 |
32 |
16 |
8 |
4 |
2 |
1 |
|
integer 16 = |
0 |
0 |
1 |
0 |
0 |
0 |
0 |
integer 32 = |
0 |
1 |
0 |
0 |
0 |
0 |
0 |
result of '16 | 32' = |
0 |
1 |
1 |
0 |
0 |
0 |
0 |
The Bitor command then converts this new binary value (0110000) to its integer value (48), so this formula returns the number 48.
IF ([A1] = 5) | ([B1] = 10), "Department A", "Department B"
If cell [A1] equals 5 Or cell [B1] equals 10, return the string value "Department A". Otherwise, return the string value "Department B".
IF [A1] > 5, MyNVar "Comparison1" = 1, MyNVar "Comparison1" = 0 :
IF [B1] < 10, MyNVar "Comparison2" = 1, MyNVar "Comparison2" = 0 :
IF MyNVar "Comparison1" | MyNVar "Comparison2", "Department A", "Department B"
If cell [A1] is greater than 5 Or cell [B1] is less than 10, return the string value "Department A". Otherwise, return the string value "Department B".
IF (IF [A1] > 5, 1, 0) | (IF [B1] < 10, 1, 0), "Department A", "Department B"
If cell [A1] is greater than 5 Or cell [B1] is less than 10, return the string value "Department A". Otherwise, return the string value "Department B".