bc.bit

Broadcasted Bit-wise Operations

Description

The bc.bit() function 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 or arrays.
op a single string, giving the operator.
Supported bit-wise operators: &, |, xor, nand, ==, !=, <, >, <=, >=, <<, >>.
further arguments passed to or from methods.

Details

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

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

  • "==" is equivalent to bit-wise (x & y) | (!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) | (y == x), but faster;

  • ">=" is equivalent to bit-wise (x & !y) | (y == x), 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.

Examples

library("broadcast")

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, "&")
## , , 1
## 
##      [,1] [,2] [,3]
## [1,]   00   00   08
## [2,]   01   01   09
## [3,]   00   00   08
## [4,]   03   07   00
## 
## , , 2
## 
##      [,1] [,2] [,3]
## [1,]   00   00   08
## [2,]   00   00   08
## [3,]   00   00   00
## [4,]   04   00   01
bc.bit(x, y, "|")
## , , 1
## 
##      [,1] [,2] [,3]
## [1,]   0a   0e   0a
## [2,]   09   0d   09
## [3,]   0a   0e   0a
## [4,]   07   07   07
## 
## , , 2
## 
##      [,1] [,2] [,3]
## [1,]   0b   0f   0b
## [2,]   0b   0f   0b
## [3,]   0b   0f   08
## [4,]   07   0f   07
bc.bit(x, y, "xor")
## , , 1
## 
##      [,1] [,2] [,3]
## [1,]   0a   0e   02
## [2,]   08   0c   00
## [3,]   0a   0e   02
## [4,]   04   00   07
## 
## , , 2
## 
##      [,1] [,2] [,3]
## [1,]   0b   0f   03
## [2,]   0b   0f   03
## [3,]   0b   0f   08
## [4,]   03   0f   06