EVOLUTION-MANAGER
Edit File: rawConversion.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Convert to or from Raw Vectors</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for rawConversion {base}"><tr><td>rawConversion {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Convert to or from Raw Vectors</h2> <h3>Description</h3> <p>Conversion and manipulation of objects of type <code>"raw"</code>. </p> <h3>Usage</h3> <pre> charToRaw(x) rawToChar(x, multiple = FALSE) rawShift(x, n) rawToBits(x) intToBits(x) packBits(x, type = c("raw", "integer")) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>object to be converted or shifted.</p> </td></tr> <tr valign="top"><td><code>multiple</code></td> <td> <p>logical: should the conversion be to a single character string or multiple individual characters?</p> </td></tr> <tr valign="top"><td><code>n</code></td> <td> <p>the number of bits to shift. Positive numbers shift right and negative numbers shift left: allowed values are <code>-8 ... 8</code>.</p> </td></tr> <tr valign="top"><td><code>type</code></td> <td> <p>the result type, partially matched.</p> </td></tr> </table> <h3>Details</h3> <p><code>packBits</code> accepts raw, integer or logical inputs, the last two without any NAs. </p> <p>Note that ‘bytes’ are not necessarily the same as characters, e.g. in UTF-8 locales. </p> <h3>Value</h3> <p><code>charToRaw</code> converts a length-one character string to raw bytes. It does so without taking into account any declared encoding (see <code><a href="Encoding.html">Encoding</a></code>). </p> <p><code>rawToChar</code> converts raw bytes either to a single character string or a character vector of single bytes (with <code>""</code> for <code>0</code>). (Note that a single character string could contain embedded nuls; only trailing nulls are allowed and will be removed.) In either case it is possible to create a result which is invalid in a multibyte locale, e.g. one using UTF-8. <a href="LongVectors.html">Long vectors</a> are allowed if <code>multiple</code> is true. </p> <p><code>rawShift(x, n)</code> shift the bits in <code>x</code> by <code>n</code> positions to the right, see the argument <code>n</code>, above. </p> <p><code>rawToBits</code> returns a raw vector of 8 times the length of a raw vector with entries 0 or 1. <code>intToBits</code> returns a raw vector of 32 times the length of an integer vector with entries 0 or 1. (Non-integral numeric values are truncated to integers.) In both cases the unpacking is least-significant bit first. </p> <p><code>packBits</code> packs its input (using only the lowest bit for raw or integer vectors) least-significant bit first to a raw or integer vector. </p> <h3>Examples</h3> <pre> x <- "A test string" (y <- charToRaw(x)) is.vector(y) # TRUE rawToChar(y) rawToChar(y, multiple = TRUE) (xx <- c(y, charToRaw("&"), charToRaw("more"))) rawToChar(xx) rawShift(y, 1) rawShift(y, -2) rawToBits(y) showBits <- function(r) stats::symnum(as.logical(rawToBits(r))) z <- as.raw(5) z ; showBits(z) showBits(rawShift(z, 1)) # shift to right showBits(rawShift(z, 2)) showBits(z) showBits(rawShift(z, -1)) # shift to left showBits(rawShift(z, -2)) # .. showBits(rawShift(z, -3)) # shifted off entirely </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>