EVOLUTION-MANAGER
Edit File: bitwise.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: Bitwise Logical Operations</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 bitwise {base}"><tr><td>bitwise {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Bitwise Logical Operations</h2> <h3>Description</h3> <p>Logical operations on integer vectors with elements viewed as sets of bits. </p> <h3>Usage</h3> <pre> bitwNot(a) bitwAnd(a, b) bitwOr(a, b) bitwXor(a, b) bitwShiftL(a, n) bitwShiftR(a, n) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>a, b</code></td> <td> <p>integer vectors; numeric vectors are coerced to integer vectors.</p> </td></tr> <tr valign="top"><td><code>n</code></td> <td> <p>non-negative integer vector of values up to 31.</p> </td></tr> </table> <h3>Details</h3> <p>Each element of an integer vector has 32 bits. </p> <p>Pairwise operations can result in integer <code>NA</code>. </p> <p>Shifting is done assuming the values represent unsigned integers. </p> <h3>Value</h3> <p>An integer vector of length the longer of the arguments, or zero length if one is zero-length. </p> <p>The output element is <code>NA</code> if an input is <code>NA</code> (after coercion) or an invalid shift. </p> <h3>See Also</h3> <p>The logical operators, <code><a href="Logic.html">!</a></code>, <code><a href="Logic.html">&</a></code>, <code><a href="Logic.html">|</a></code>, <code><a href="Logic.html">xor</a></code>. Notably these <em>do</em> work bitwise for <code><a href="raw.html">raw</a></code> arguments. </p> <p>The classes <code>"<a href="octmode.html">octmode</a>"</code> and <code>"<a href="hexmode.html">hexmode</a>"</code> whose implementation of the standard logical operators is based on these functions. </p> <p>Package <a href="https://CRAN.R-project.org/package=bitops"><span class="pkg">bitops</span></a> has similar functions for numeric vectors which differ in the way they treat integers <i>2^31</i> or larger. </p> <h3>Examples</h3> <pre> bitwNot(0:12) # -1 -2 ... -13 bitwAnd(15L, 7L) # 7 bitwOr (15L, 7L) # 15 bitwXor(15L, 7L) # 8 bitwXor(-1L, 1L) # -2 ## The "same" for 'raw' instead of integer : rr12 <- as.raw(0:12) ; rbind(rr12, !rr12) c(r15 <- as.raw(15), r7 <- as.raw(7)) # 0f 07 r15 & r7 # 07 r15 | r7 # 0f xor(r15, r7)# 08 bitwShiftR(-1, 1:31) # shifts of 2^32-1 = 4294967295 </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>