You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
163 lines
8.2 KiB
HTML
163 lines
8.2 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html>
|
|
<!-- This manual describes how to install and use the GNU multiple precision
|
|
arithmetic library, version 6.1.0.
|
|
|
|
Copyright 1991, 1993-2015 Free Software Foundation, Inc.
|
|
|
|
Permission is granted to copy, distribute and/or modify this document under
|
|
the terms of the GNU Free Documentation License, Version 1.3 or any later
|
|
version published by the Free Software Foundation; with no Invariant Sections,
|
|
with the Front-Cover Texts being "A GNU Manual", and with the Back-Cover
|
|
Texts being "You have freedom to copy and modify this GNU Manual, like GNU
|
|
software". A copy of the license is included in
|
|
GNU Free Documentation License. -->
|
|
<!-- Created by GNU Texinfo 6.4, http://www.gnu.org/software/texinfo/ -->
|
|
<head>
|
|
<title>Integer Logic and Bit Fiddling (GNU MP 6.1.0)</title>
|
|
|
|
<meta name="description" content="How to install and use the GNU multiple precision arithmetic library, version 6.1.0.">
|
|
<meta name="keywords" content="Integer Logic and Bit Fiddling (GNU MP 6.1.0)">
|
|
<meta name="resource-type" content="document">
|
|
<meta name="distribution" content="global">
|
|
<meta name="Generator" content="makeinfo">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
|
<link href="index.html#Top" rel="start" title="Top">
|
|
<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
|
|
<link href="Integer-Functions.html#Integer-Functions" rel="up" title="Integer Functions">
|
|
<link href="I_002fO-of-Integers.html#I_002fO-of-Integers" rel="next" title="I/O of Integers">
|
|
<link href="Integer-Comparisons.html#Integer-Comparisons" rel="prev" title="Integer Comparisons">
|
|
<style type="text/css">
|
|
<!--
|
|
a.summary-letter {text-decoration: none}
|
|
blockquote.indentedblock {margin-right: 0em}
|
|
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
|
|
blockquote.smallquotation {font-size: smaller}
|
|
div.display {margin-left: 3.2em}
|
|
div.example {margin-left: 3.2em}
|
|
div.lisp {margin-left: 3.2em}
|
|
div.smalldisplay {margin-left: 3.2em}
|
|
div.smallexample {margin-left: 3.2em}
|
|
div.smalllisp {margin-left: 3.2em}
|
|
kbd {font-style: oblique}
|
|
pre.display {font-family: inherit}
|
|
pre.format {font-family: inherit}
|
|
pre.menu-comment {font-family: serif}
|
|
pre.menu-preformatted {font-family: serif}
|
|
pre.smalldisplay {font-family: inherit; font-size: smaller}
|
|
pre.smallexample {font-size: smaller}
|
|
pre.smallformat {font-family: inherit; font-size: smaller}
|
|
pre.smalllisp {font-size: smaller}
|
|
span.nolinebreak {white-space: nowrap}
|
|
span.roman {font-family: initial; font-weight: normal}
|
|
span.sansserif {font-family: sans-serif; font-weight: normal}
|
|
ul.no-bullet {list-style: none}
|
|
-->
|
|
</style>
|
|
|
|
|
|
</head>
|
|
|
|
<body lang="en">
|
|
<a name="Integer-Logic-and-Bit-Fiddling"></a>
|
|
<div class="header">
|
|
<p>
|
|
Next: <a href="I_002fO-of-Integers.html#I_002fO-of-Integers" accesskey="n" rel="next">I/O of Integers</a>, Previous: <a href="Integer-Comparisons.html#Integer-Comparisons" accesskey="p" rel="prev">Integer Comparisons</a>, Up: <a href="Integer-Functions.html#Integer-Functions" accesskey="u" rel="up">Integer Functions</a> [<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
|
|
</div>
|
|
<hr>
|
|
<a name="Logical-and-Bit-Manipulation-Functions"></a>
|
|
<h3 class="section">5.11 Logical and Bit Manipulation Functions</h3>
|
|
<a name="index-Logical-functions"></a>
|
|
<a name="index-Bit-manipulation-functions"></a>
|
|
<a name="index-Integer-logical-functions"></a>
|
|
<a name="index-Integer-bit-manipulation-functions"></a>
|
|
|
|
<p>These functions behave as if twos complement arithmetic were used (although
|
|
sign-magnitude is the actual implementation). The least significant bit is
|
|
number 0.
|
|
</p>
|
|
<dl>
|
|
<dt><a name="index-mpz_005fand"></a>Function: <em>void</em> <strong>mpz_and</strong> <em>(mpz_t <var>rop</var>, const mpz_t <var>op1</var>, const mpz_t <var>op2</var>)</em></dt>
|
|
<dd><p>Set <var>rop</var> to <var>op1</var> bitwise-and <var>op2</var>.
|
|
</p></dd></dl>
|
|
|
|
<dl>
|
|
<dt><a name="index-mpz_005fior"></a>Function: <em>void</em> <strong>mpz_ior</strong> <em>(mpz_t <var>rop</var>, const mpz_t <var>op1</var>, const mpz_t <var>op2</var>)</em></dt>
|
|
<dd><p>Set <var>rop</var> to <var>op1</var> bitwise inclusive-or <var>op2</var>.
|
|
</p></dd></dl>
|
|
|
|
<dl>
|
|
<dt><a name="index-mpz_005fxor"></a>Function: <em>void</em> <strong>mpz_xor</strong> <em>(mpz_t <var>rop</var>, const mpz_t <var>op1</var>, const mpz_t <var>op2</var>)</em></dt>
|
|
<dd><p>Set <var>rop</var> to <var>op1</var> bitwise exclusive-or <var>op2</var>.
|
|
</p></dd></dl>
|
|
|
|
<dl>
|
|
<dt><a name="index-mpz_005fcom"></a>Function: <em>void</em> <strong>mpz_com</strong> <em>(mpz_t <var>rop</var>, const mpz_t <var>op</var>)</em></dt>
|
|
<dd><p>Set <var>rop</var> to the one’s complement of <var>op</var>.
|
|
</p></dd></dl>
|
|
|
|
<dl>
|
|
<dt><a name="index-mpz_005fpopcount"></a>Function: <em>mp_bitcnt_t</em> <strong>mpz_popcount</strong> <em>(const mpz_t <var>op</var>)</em></dt>
|
|
<dd><p>If <em><var>op</var>>=0</em>, return the population count of <var>op</var>, which is the
|
|
number of 1 bits in the binary representation. If <em><var>op</var><0</em>, the
|
|
number of 1s is infinite, and the return value is the largest possible
|
|
<code>mp_bitcnt_t</code>.
|
|
</p></dd></dl>
|
|
|
|
<dl>
|
|
<dt><a name="index-mpz_005fhamdist"></a>Function: <em>mp_bitcnt_t</em> <strong>mpz_hamdist</strong> <em>(const mpz_t <var>op1</var>, const mpz_t <var>op2</var>)</em></dt>
|
|
<dd><p>If <var>op1</var> and <var>op2</var> are both <em>>=0</em> or both <em><0</em>, return the
|
|
hamming distance between the two operands, which is the number of bit positions
|
|
where <var>op1</var> and <var>op2</var> have different bit values. If one operand is
|
|
<em>>=0</em> and the other <em><0</em> then the number of bits different is
|
|
infinite, and the return value is the largest possible <code>mp_bitcnt_t</code>.
|
|
</p></dd></dl>
|
|
|
|
<dl>
|
|
<dt><a name="index-mpz_005fscan0"></a>Function: <em>mp_bitcnt_t</em> <strong>mpz_scan0</strong> <em>(const mpz_t <var>op</var>, mp_bitcnt_t <var>starting_bit</var>)</em></dt>
|
|
<dt><a name="index-mpz_005fscan1"></a>Function: <em>mp_bitcnt_t</em> <strong>mpz_scan1</strong> <em>(const mpz_t <var>op</var>, mp_bitcnt_t <var>starting_bit</var>)</em></dt>
|
|
<dd><a name="index-Bit-scanning-functions"></a>
|
|
<a name="index-Scan-bit-functions"></a>
|
|
<p>Scan <var>op</var>, starting from bit <var>starting_bit</var>, towards more significant
|
|
bits, until the first 0 or 1 bit (respectively) is found. Return the index of
|
|
the found bit.
|
|
</p>
|
|
<p>If the bit at <var>starting_bit</var> is already what’s sought, then
|
|
<var>starting_bit</var> is returned.
|
|
</p>
|
|
<p>If there’s no bit found, then the largest possible <code>mp_bitcnt_t</code> is
|
|
returned. This will happen in <code>mpz_scan0</code> past the end of a negative
|
|
number, or <code>mpz_scan1</code> past the end of a nonnegative number.
|
|
</p></dd></dl>
|
|
|
|
<dl>
|
|
<dt><a name="index-mpz_005fsetbit"></a>Function: <em>void</em> <strong>mpz_setbit</strong> <em>(mpz_t <var>rop</var>, mp_bitcnt_t <var>bit_index</var>)</em></dt>
|
|
<dd><p>Set bit <var>bit_index</var> in <var>rop</var>.
|
|
</p></dd></dl>
|
|
|
|
<dl>
|
|
<dt><a name="index-mpz_005fclrbit"></a>Function: <em>void</em> <strong>mpz_clrbit</strong> <em>(mpz_t <var>rop</var>, mp_bitcnt_t <var>bit_index</var>)</em></dt>
|
|
<dd><p>Clear bit <var>bit_index</var> in <var>rop</var>.
|
|
</p></dd></dl>
|
|
|
|
<dl>
|
|
<dt><a name="index-mpz_005fcombit"></a>Function: <em>void</em> <strong>mpz_combit</strong> <em>(mpz_t <var>rop</var>, mp_bitcnt_t <var>bit_index</var>)</em></dt>
|
|
<dd><p>Complement bit <var>bit_index</var> in <var>rop</var>.
|
|
</p></dd></dl>
|
|
|
|
<dl>
|
|
<dt><a name="index-mpz_005ftstbit"></a>Function: <em>int</em> <strong>mpz_tstbit</strong> <em>(const mpz_t <var>op</var>, mp_bitcnt_t <var>bit_index</var>)</em></dt>
|
|
<dd><p>Test bit <var>bit_index</var> in <var>op</var> and return 0 or 1 accordingly.
|
|
</p></dd></dl>
|
|
|
|
<hr>
|
|
<div class="header">
|
|
<p>
|
|
Next: <a href="I_002fO-of-Integers.html#I_002fO-of-Integers" accesskey="n" rel="next">I/O of Integers</a>, Previous: <a href="Integer-Comparisons.html#Integer-Comparisons" accesskey="p" rel="prev">Integer Comparisons</a>, Up: <a href="Integer-Functions.html#Integer-Functions" accesskey="u" rel="up">Integer Functions</a> [<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
|
|
</div>
|
|
|
|
|
|
|
|
</body>
|
|
</html>
|