rawConversion
Convert to or from Raw Vectors

Description

Utilities for raw vectors conversion, shifting, and packing.

Usage

charToRaw(x)
rawToChar(x, multiple = FALSE)
rawToBits(x)
intToBits(x)
packBits(x, type = c("raw", "integer"))
rawShift(x, n)

Arguments

x a vector of data to convert, shift, or pack. See Details for its meaning in different functions.
multiple a logical value. If TRUE, the conversion should be to multiple individual characters. If FALSE, the conversion should be to a single character string.
n the number of bits to shift.
type the result type of packing. Can be "raw" or "integer". Partial character matching is allowed.

Details

Value
charToRawreturns a raw vector of bytes.
rawToCharreturns a single character string or a character vector of single multiple individual characters.
rawToBitsreturns a raw vector of 8 times length of x.
intToBitsreturns a raw vector of 32 times length of x.
packBitsreturns a raw or integer vector of length length(x)/8 or length(x)/32.
rawShiftreturns a raw vector of the same length of x.
See Also
raw, Encoding
Examples
x <- charToRaw("abc")
x
# prints [1] 61 62 63

rawToChar(x) # returns "abc"

rawToChar(x, multiple = TRUE) # returns c("a","b","c")

rawToBits(as.raw(0x5)) # [1] 01 00 01 00 00 00 00 00

intToBits(6) # [1] 00 01 01 00 00 00 00 00 00 00 00 00 00 00 00 00 # [17] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

packBits(as.raw(1:3)) # Error: argument 'x' must be a multiple of 8 long

packBits(as.raw(1:8)) # [1] 55

packBits(as.raw(1:32),"integer") # [1] 1431655765

rawShift(as.raw(0x03), 1) # [1] 06

rawShift(as.raw(0x80), -3) # [1] 10

Package base version 4.0.0-28
Package Index