The Math Bit-wise OR operator ( | ) indicates whether either operands
is TRUE. A discrete operand is considered TRUE if it is ON; a numeric
operand is considered TRUE if its value is non-zero.
Note:
bit-wise OR operations are typically only used for unsigned hexadecimal
values and unsigned integer memory locations. Using the :U cast operator on signed 16-bit values will
cause them to be processed as unsigned 16-bit values. There is no unsigned
cast operation for 32-bit signed values.
The operands can be any mix of signed integers, unsigned integers, real
(floating point) numbers or discrete values. They can be any numeric or
discrete memory location, or any numeric or discrete structure member.
All discrete values and all 16-bit integer values are promoted to 32-bit
2's complement signed integer values. If a Real value is included in the
equation then all of the values will be promoted to Real values and all
calculations will be performed using Real numbers.
Traditional math precedence rules are used to solve the math expression.
The use of parentheses to remove any ambiguity in the processing order
is encouraged.
Refer to the examples below:
Unsigned Integers: assume V= 0x1234 and V1 = 0x5678
|
V2 = V0 | V1
|
V0 = 0x1234 | 0x5678
V0 = 0001_0010_0011_0100 (0x1234) V1 = 0101_0110_0111_1000 (0x5678)
V0 = 0101_0110_0111_1100 (0x567C)
|
Both operands are unsigned integer memory locations.
The result is placed in an unsigned integer memory location.
|
As stated earlier, bit-wise operations
are intended for use on Unsigned integer values, NOT Signed integer values
or Real values. The following examples are here only to provide understanding
in how these values will be processed by the math stack, the result that
is generated is typically not useful.
>Signed Integers:
assume D0 = 12345678 and N0 = 1234 and N1 = -1234
|
D1 = D0 | N0
|
D0 = 12345678 | 1234
D0 = 0000_0000_1011_1100_0110_0001_0100_1110 (12345678) N0 = 0000_0000_0000_0000_0000_0100_1101_0010
(1234)
D1 = 0000_0000_1011_1100_0110_0101_1101_1110 (12346846)
|
Both operands are signed integer memory locations.
When the 16-bit positive value is loaded into the math stack it will
be promoted to a 32-bit value by sign extending using 0's in the upper
16 bits.
The result is placed in a signed integer memory location.
|
D1 = D0 | N1
|
D0 = 12345678 | -1234
D0 = 0000_0000_1011_1100_0110_0001_0100_1110 (12345678) N1 = 1111_1111_1111_1111_1111_1011_0010_1110
(-1234)
D1 = 1111_1111_1111_1111_1111_1011_0110_1110 (-1170)
|
Both operands are signed integer memory locations.
When the 16-bit negative value is loaded into the math stack it will
be promoted to a 32-bit 2's complement value by sign extending using 1's
in the upper 16 bits.
The result is placed in a signed integer memory location.
|
D1 = D0 | N1:U
|
D0 = 12345678 | -1234:U
D0 = 0000_0000_1011_1100_0110_0001_0100_1110 (12345678) N1 = 0000_0000_0000_0000_1111_1011_0010_1110
(64302)
D1 = 0000_0000_1011_1100_1111_1011_0110_1110 (12385134)
|
Both operands are signed integer memory locations.
The 16-bit negative signed value is using the :U cast
operator which will interpret the 16th bit as part of the value instead
of the sign bit. When it is loaded into the math stack it will be promoted
to a 32-bit 2's complement value by sign extending using 0's in the upper
16 bits.
The result is placed in a signed integer memory location.
|
Real: assume D0 = 12345678 and R0 = 123456.789
|
D1 = D0 | R0
|
D0 = 12345678 | 123456.789
D0 = 0000_0000_1011_1100_0110_0001_0100_1110 (12345678) R0 = 0000_0000_0000_0001_1110_0010_0100_0000 (123456)
D1 = 0000_0000_1011_1101_1110_0011_0100_1110 (12444494)
|
One operand in a signed integer memory location,
the other is a Real memory location.
When the Real value in R0 is loaded into the math stack it will be demoted
to a 32-bit 2's complement value which will ignore the fractional portion
of the Real value.
The result is placed in a signed integer memory location.
|
|