\HeaderA{rawConversion}{Convert to or from Raw Vectors}{rawConversion}
\aliasA{charToRaw}{rawConversion}{charToRaw}
\aliasA{intToBits}{rawConversion}{intToBits}
\aliasA{packBits}{rawConversion}{packBits}
\aliasA{rawShift}{rawConversion}{rawShift}
\aliasA{rawToBits}{rawConversion}{rawToBits}
\aliasA{rawToChar}{rawConversion}{rawToChar}
\keyword{classes}{rawConversion}
\begin{Description}\relax
Conversion and manipulation of  objects of type \code{"raw"}.
\end{Description}
\begin{Usage}
\begin{verbatim}
charToRaw(x)
rawToChar(x, multiple = FALSE)

rawShift(x, n)

rawToBits(x)
intToBits(x)
packBits(x, type = c("raw", "integer"))
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] object to be converted or shifted.
\item[\code{multiple}] logical: should the conversion be to a single
character string or multiple individual characters?
\item[\code{n}] the number of bits to shift.  Positive numbers shift right
and negative numbers shift left: allowed values are \code{-8 ... 8}.
\item[\code{type}] the result type.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
\code{packBits} accepts raw, integer or logical inputs, the last two
without any NAs.

Note that \sQuote{bytes} are not necessarily the same as characters,
e.g. in UTF-8 domains.
\end{Details}
\begin{Value}
\code{charToRaw} converts a length-one character string to raw bytes.
It does so without taking into account any declared encoding (see
\code{\LinkA{Encoding}{Encoding}}).

\code{rawToChar} converts raw bytes either to a single character
string or a character vector of single bytes.  (Note that a single
character string could contain embedded nuls.)

\code{rawToBits} returns a raw vector of 8 times the length of a raw
vector with entries 0 or 1.  \code{intToBits} returns a raw vector
of 32 times the length of an integer vector with entries 0 or 1. In
both cases the unpacking is least-significant bit first.

\code{packbits} packs its input (using only the lowest bit for raw or
integer vectors) least-significant bit first to a raw or integer vector.
\end{Value}
\begin{Examples}
\begin{ExampleCode}
x <- "A test string"
(y <- charToRaw(x))
is.vector(y) # TRUE

rawToChar(y)
rawToChar(y, multiple = TRUE)
(xx <- c(y, as.raw(0), charToRaw("more")))
rawToChar(xx)
xxx <- xx
xxx[length(y)+1] <- charToRaw("&")
xxx
rawToChar(xxx)

rawShift(y, 1)
rawShift(y, -2)

rawToBits(y)
\end{ExampleCode}
\end{Examples}

