bc.bit: Broadcasted Bit-wise Operations

bc.bitR Documentation

Broadcasted Bit-wise Operations

Description

The bc.bit() method performs broadcasted bit-wise operations on pairs of arrays, where both arrays are of type raw or both arrays are of type integer.

Usage

bc.bit(x, y, op, ...)

## S4 method for signature 'ANY'
bc.bit(x, y, op)

Arguments

x, y

conformable raw or integer (32 bit) vectors/arrays.

op

a single string, giving the operator.
Supported bit-wise operators: &, |, xor, nand, nor, <<, >>, ==, !=, <, >, <=, >=.
"nand" is defined as bit-wise !(x & y), and "nor" is defined as bit-wise !(x | y).

...

further arguments passed to or from methods.

Details

The "&", "|", "xor", "nand", and "nor" operators given in bc.bit() perform BIT-WISE AND, OR, XOR, NAND, and NOR operations, respectively.

The relational operators given in bc.bit() perform BIT-WISE relational operations:

  • "==" is equivalent to bit-wise !xor(x, y), but faster;

  • "!=" is equivalent to bit-wise xor(x, y);

  • "<" is equivalent to bit-wise (!x & y), but faster;

  • ">" is equivalent to bit-wise (x & !y), but faster;

  • "<=" is equivalent to bit-wise (!x | y), but faster;

  • ">=" is equivalent to bit-wise (x | !y), but faster.

The "<<" and ">>" operators perform bit-wise left-shift and right-shift, respectively, on x by unit y.
For these shift operations, y being larger than the number of bits of x results in an error.
Shift operations are only supported for type of raw.

Value

For bit-wise operators:
An array of the same type as x and y, as a result of the broadcasted bit-wise operation.

Note

bc.bit(x, x, "nand") and bc.bit(x, x, "nor") are equivalent to bit-wise negation of x.
I.e.:
!x if x is type of raw, or bitwNot(x) if x is type of integer.

See Also

broadcast_operators

Examples

x.dim <- c(4:2)
x.len <- prod(x.dim)
x.data <- as.raw(0:10)
y.data <- as.raw(10:0)
x <- array(x.data, x.dim)
y <- array(y.data, c(4,1,1))

bc.bit(x, y, "&")
bc.bit(x, y, "|")
bc.bit(x, y, "xor")


broadcast documentation built on Oct. 4, 2026, 5:07 p.m.

Related to bc.bit in broadcast...