bits_to_raw {bitstreamio}R Documentation

Convert between logical vector of bits and raw vector

Description

Convert between logical vector of bits and raw vector

Usage

bits_to_raw(bits, msb_first = TRUE)

raw_to_bits(x, msb_first = TRUE)

Arguments

bits

Logical vector of bit values. Length must be a multiple of 8

msb_first

MSB first? Default: TRUE

x

Byte values. Integer vectors will be truncated to 8 bits before output. Numeric vectors will be rounded to integers and then truncated to 8 bits. Raw vectors preferred.

Value

Logical vector of bit values or a raw vector.

Examples

bits <- raw_to_bits(c(0, 4, 21))
bits
bits_to_raw(bits) |> as.integer()

[Package bitstreamio version 0.1.0 Index]