bitwNot
Bitwise Logical Operations

Description

Bitwise logical operations in elements of integer vectors.

Usage

bitwNot(a)
bitwAnd(a, b)
bitwOr(a, b)
bitwXor(a, b)
bitwShiftL(a, n)
bitwShiftR(a, n)

Arguments

a, b integer vectors. Other non-integer numerics will be coerced to integers. NA elements are allowed.
n an integer vector with each element specifying the number of bits to shift left or right. Valid values are 0 to 30 (for bitwShiftL) and 0 to 31 (for bitwShiftR). Other values will produce NA results.

Details

These functions perform bitwise logical operations on 32-bit integers, similar to the logical operations on the octmode and hexmode classes.
Each element of a and b (or n) must be (or can be coerced to) integer or NA. If a and b (or n) have different lengths, the smaller one will be recycled to match the longer one.
For bitwShiftL and bitwShiftR, each element in a is treated as an unsigned integer before shifting.
Value
bitwNot returns an integer vector with same length as a.
The other functions return an integer vector whose length is the longer one of a and b (or n), or an empty vector if one of the arguments is empty.
See Also
Logic, octmode, hexmode
Examples
bitwNot(c(2, -6, NA, 3, 6))  #  -3  5 NA -4 -7
bitwAnd(c(2, -3, 0, NA, 1,5), 1:8) #  0  0  0 NA  1  4  2  8
bitwOr(c(2, -3, 0, NA, 1,5), 1:8) #   3 -1  3 NA  5  7  7 -3
bitwXor(c(2, -3, 0, NA, 1,5), 1:8) #    3  -1   3  NA   4   3   5 -11
bitwOr(integer(0), 1:9) # integer(0)

bitwShiftL(c(2, -3, 0, NA, 1,5), 1:4) # 4 -12 0 NA 2 20 bitwShiftR(c(2, -3, 0, NA, 1,5), 1:4) # 1 1073741823 0 NA 0 1 bitwShiftL(1:3, -5) # NA NA NA bitwShiftR(1:3, 35) # NA NA NA

Package base version 6.1.1-7
Package Index