bit (version 1.1-15.1)

LogicBit: Boolean operators and functions for class bit

Description

Boolean 'negation', 'and', 'or' and 'exclusive or'.

Usage

# S3 method for bit
!(x)
# S3 method for bitwhich
!(x)
# S3 method for bit
&(e1, e2)
# S3 method for bitwhich
&(e1, e2)
# S3 method for bit
|(e1, e2)
# S3 method for bitwhich
|(e1, e2)
# S3 method for bit
==(e1, e2)
# S3 method for bitwhich
==(e1, e2)
# S3 method for bit
!=(e1, e2)
# S3 method for bitwhich
!=(e1, e2)
xor(x, y)
# S3 method for default
xor(x, y)
# S3 method for bit
xor(x, y)
# S3 method for bitwhich
xor(x, y)

Arguments

x

a bit vector (or one logical vector in binary operators)

y

a bit vector or an logical vector

e1

a bit vector or an logical vector

e2

a bit vector or an logical vector

Value

An object of class 'bit' (or 'bitwhich')

Details

Binary operators and function xor can combine 'bit' objects and 'logical' vectors. They do not recycle, thus the lengths of objects must match. Boolean operations on bit vectors are extremely fast because they are implemented using C's bitwise operators. If one argument is 'logical' it is converted to 'bit'.

Binary operators and function xor can combine 'bitwhich' objects and other vectors. They do not recycle, thus the lengths of objects must match. Boolean operations on bitwhich vectors are fast if the distribution of TRUE and FALSE is very asymetric. If one argument is not 'bitwhich' it is converted to 'bitwhich'.

The xor function has been made generic and xor.default has been implemented much faster than R's standard xor. This was possible because actually boolean function xor and comparison operator != do the same (even with NAs), and != is much faster than the multiple calls in (x | y) & !(x & y)

See Also

bit, Logic

Examples

Run this code
# NOT RUN {
  x <- as.bit(c(FALSE, FALSE, FALSE, NA, NA, NA, TRUE, TRUE, TRUE))
  yl <- c(FALSE, NA, TRUE, FALSE, NA, TRUE, FALSE, NA, TRUE)
  y <- as.bit(yl)
  !x
  x & y
  x | y
  xor(x, y)
  x != y
  x == y
  x & yl
  x | yl
  xor(x, yl)
  x != yl
  x == yl

  x <- as.bitwhich(c(FALSE, FALSE, FALSE, NA, NA, NA, TRUE, TRUE, TRUE))
  yl <- c(FALSE, NA, TRUE, FALSE, NA, TRUE, FALSE, NA, TRUE)
  y <- as.bitwhich(yl)
  !x
  x & y
  x | y
  xor(x, y)
  x != y
  x == y
  x & yl
  x | yl
  xor(x, yl)
  x != yl
  x == yl
# }

Run the code above in your browser using DataCamp Workspace