
#use wml::openssl-macros area=docs page=BN_set_bit

<title>Documents, BN_set_bit(3)</title>

<h1>BN_set_bit(3)</h1>

#use wml::imp::generic

{:
## What's this? [[s|(<STRONG>[^<].+?)</A>(</STRONG><DD>)|$1$2|sg]]
[[s|<P>\s+<P>|<P>|sg]]
[[s|<P>\s+</|</|sg]]
[[s|<DD>\s*<DT>|<DD>&nbsp;<DT>|sg]]
[[s|<DD>\s*</DL>|<DD>&nbsp;</DL>|sg]]
[[s|\[|&#91;|sg]]
[[s|\]|&#93;|sg]]

<!-- INDEX BEGIN -->

<UL>

	<LI><A HREF="#NAME">NAME</A>
	<LI><A HREF="#SYNOPSIS">SYNOPSIS</A>
	<LI><A HREF="#DESCRIPTION">DESCRIPTION</A>
	<LI><A HREF="#RETURN_VALUES">RETURN VALUES</A>
	<LI><A HREF="#SEE_ALSO">SEE ALSO</A>
	<LI><A HREF="#HISTORY">HISTORY</A>
</UL>
<!-- INDEX END -->

<HR>
<P>
<HR>
<H1><A NAME="NAME">NAME</A></H1>
<P>
BN_set_bit, BN_clear_bit, BN_is_bit_set, BN_mask_bits, BN_lshift,
BN_lshift1, BN_rshift, BN_rshift1 - bit operations on BIGNUMs

</P>
<P>
<HR>
<H1><A NAME="SYNOPSIS">SYNOPSIS</A></H1>
<PRE> #include &lt;openssl/bn.h&gt;
</PRE>
<PRE> int BN_set_bit(BIGNUM *a, int n);
 int BN_clear_bit(BIGNUM *a, int n);
</PRE>
<PRE> int BN_is_bit_set(const BIGNUM *a, int n);
</PRE>
<PRE> int BN_mask_bits(BIGNUM *a, int n);
</PRE>
<PRE> int BN_lshift(BIGNUM *r, const BIGNUM *a, int n);
 int BN_lshift1(BIGNUM *r, BIGNUM *a);
</PRE>
<PRE> int BN_rshift(BIGNUM *r, BIGNUM *a, int n);
 int BN_rshift1(BIGNUM *r, BIGNUM *a);
</PRE>
<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></H1>
<P>
<CODE>BN_set_bit()</CODE> sets bit <STRONG>n</STRONG> in <STRONG>a</STRONG> to 1 (<CODE>a|=(1&amp;lt;&amp;lt;n)</CODE>). The number is expanded if necessary.

</P>
<P>
<CODE>BN_clear_bit()</CODE> sets bit <STRONG>n</STRONG> in <STRONG>a</STRONG> to 0 (<CODE>a&amp;=~(1&amp;lt;&amp;lt;n)</CODE>). An error occurs if <STRONG>a</STRONG> is shorter than <STRONG>n</STRONG> bits.

</P>
<P>
<CODE>BN_is_bit_set()</CODE> tests if bit <STRONG>n</STRONG> in <STRONG>a</STRONG> is set.

</P>
<P>
<CODE>BN_mask_bits()</CODE> truncates <STRONG>a</STRONG> to an <STRONG>n</STRONG> bit number (<CODE>a&amp;=~((~0)&amp;gt;&amp;gt;n)</CODE>). An error occurs if <STRONG>a</STRONG> already is shorter than <STRONG>n</STRONG> bits.

</P>
<P>
<CODE>BN_lshift()</CODE> shifts <STRONG>a</STRONG> left by <STRONG>n</STRONG> bits and places the result in
<STRONG>r</STRONG> (<CODE>r=a*2^n</CODE>). <CODE>BN_lshift1()</CODE> shifts <STRONG>a</STRONG> left by one and places the result in <STRONG>r</STRONG> (<CODE>r=2*a</CODE>).

</P>
<P>
<CODE>BN_rshift()</CODE> shifts <STRONG>a</STRONG> right by <STRONG>n</STRONG> bits and places the result in
<STRONG>r</STRONG> (<CODE>r=a/2^n</CODE>). <CODE>BN_rshift1()</CODE> shifts <STRONG>a</STRONG> right by one and places the result in <STRONG>r</STRONG> (<CODE>r=a/2</CODE>).

</P>
<P>
For the shift functions, <STRONG>r</STRONG> and <STRONG>a</STRONG> may be the same variable.

</P>
<P>
<HR>
<H1><A NAME="RETURN_VALUES">RETURN VALUES</A></H1>
<P>
<CODE>BN_is_bit_set()</CODE> returns 1 if the bit is set, 0 otherwise.

</P>
<P>
All other functions return 1 for success, 0 on error. The error codes can
be obtained by <A HREF="../crypto/ERR_get_error.html#">ERR_get_error(3)</A>.

</P>
<P>
<HR>
<H1><A NAME="SEE_ALSO">SEE ALSO</A></H1>
<P>
<A HREF="../crypto/bn.html#">bn(3)</A>, <A HREF="../crypto/BN_num_bytes.html#">BN_num_bytes(3)</A>, <A HREF="../crypto/BN_add.html#">BN_add(3)</A>



</P>
<P>
<HR>
<H1><A NAME="HISTORY">HISTORY</A></H1>
<P>
<CODE>BN_set_bit(),</CODE> <CODE>BN_clear_bit(),</CODE>
<CODE>BN_is_bit_set(),</CODE> <CODE>BN_mask_bits(),</CODE>
<CODE>BN_lshift(),</CODE> <CODE>BN_lshift1(),</CODE>
<CODE>BN_rshift(),</CODE> and <CODE>BN_rshift1()</CODE> are available in
all versions of SSLeay and OpenSSL.

</P>
:}

