OR
Syntax
number OR number
Description
Or, at its most primitive level, is a boolean operation, a logic function that takes in two bits and outputs a resulting bit. If given two bits, this function returns true if either bit is true, and false if both bits are false. The truth table below demonstrates all combinations of a boolean or operation:
Bit1 Bit2 Result
0 0 0
1 0 1
0 1 1
1 1 1
This holds true for conditional expressions in ARMbasic. When using "Or" encased in an If block, While loop, or Do loop, the output will behave quite literally:
IF condition1 OR condition2 THEN expression1
Is translated as:
IF condition1 IS true, OR condition2 IS true, THEN perform expression1
When given two expressions, numbers, or variables that return a number that is more than a single bit, Or is performed "bitwise". A bitwise operation compares each bit of one number, with each bit of another number, performing a logic operation for every bit. The boolean math expression below describes this:
00001111 OR
00011110
-------- equals
00011111
Notice how in the resulting number of the operation, reflects an OR operation performed on each bit of the top operand, with each corresponding bit of the bottom operand. The same logic is also used when working with conditions.
Example
numeric_value1 = 15 '00001111
numeric_value2 =
30 '00011110
'Result = 31 = 00011111
PRINT numeric_value1 OR numeric_value2
END
' Using the OR operator on two conditional expressions
numeric_value = 10
IF numeric_value = 5 OR numeric_value = 10 THEN PRINT "Numeric_Value equals 5 or 10"
END
' This will output "Numeric_Value equals 5 or 10" because
' while the first condition of the first IF statement is false, the second is true
Differences from PBASIC
- PBASIC OR is always logical, and | is bitwise