Skip to content

❗ This is a read-only mirror of the CRAN R package repository. vectorbitops — Vector Bitwise Operations

License

Notifications You must be signed in to change notification settings

cran/vectorbitops

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vectorbitops

pipeline status coverage report Latest Release

A set of minimal extensions to R's built-in bitwise operations, mainly for use with bitmasks.
This provides C functions to AND, OR or XOR a vector of integers together, to compress down to a single int. It also provides infix operators for bitwise operations, using the base functions.

If using bitops, the infix operators are redundant.

Installation

You can install the development version of vectorbitops like so:

devtools::install_gitlab("S_S_/vectorbitops")

Example

This is a basic example of use for some simple bitmasking.

library(vectorbitops)

vals <- c(
    "foo" = 1 %<<% 0,
    "bar" = 1 %<<% 1,
    "baz" = 1 %<<% 2
)

mask_a <- vals["foo"]
mask_b <- vals["baz"]
mask_c <- bit_vector_OR(vals[c("bar", "baz")])
flags <- bit_vector_OR(vals[c("foo", "bar")])

# In practise, one would just use `bitwAnd` for the below, but for demostration purposes:
bit_vector_AND(c(flags, mask_a)) # 1
bit_vector_AND(c(flags, mask_b)) # 0
bit_vector_AND(c(flags, mask_c)) # 2

About

❗ This is a read-only mirror of the CRAN R package repository. vectorbitops — Vector Bitwise Operations

Resources

License

Stars

Watchers

Forks

Packages

No packages published