---
name: "libressl-BN_set_bit"
section: "3"
platform: "linux"
package: "libressl"
version: "4.4.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libressl-BN_set_bit"
---

# libressl-BN\_set\_bit(3)

bit operations on BIGNUMs

## NAME

**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

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

**#include \<openssl/bn.h\>**

*int*\

**BN\_set\_bit**(*BIGNUM \*a*, *int n*);

*int*\

**BN\_clear\_bit**(*BIGNUM \*a*, *int n*);

*int*\

**BN\_is\_bit\_set**(*const BIGNUM \*a*, *int n*);

*int*\

**BN\_mask\_bits**(*BIGNUM \*a*, *int n*);

*int*\

**BN\_lshift**(*BIGNUM \*r*, *const BIGNUM \*a*, *int n*);

*int*\

**BN\_lshift1**(*BIGNUM \*r*, *const BIGNUM \*a*);

*int*\

**BN\_rshift**(*BIGNUM \*r*, *const BIGNUM \*a*, *int n*);

*int*\

**BN\_rshift1**(*BIGNUM \*r*, *const BIGNUM \*a*);

## DESCRIPTION

**BN\_set\_bit**() sets bit *n* in *a* to 1 (a\|=(1\<\<n)). The number is expanded if necessary.

**BN\_clear\_bit**() sets bit *n* in *a* to 0 (a&=~(1\<\<n)). An error occurs if *a* is shorter than *n* bits.

**BN\_is\_bit\_set**() tests if bit *n* in *a* is set.

**BN\_mask\_bits**() truncates *a* to an *n* bit number (a&=~((~0)\>\>n)). An error occurs if *a* already is shorter than *n* bits.

**BN\_lshift**() shifts *a* left by *n* bits and places the result in *r* (r=a\*2^n). Note that *n* must be non-negative. **BN\_lshift1**() shifts *a* left by one and places the result in *r* (r=2\*a).

**BN\_rshift**() shifts *a* right by *n* bits and places the result in *r* (r=a/2^n). Note that *n* must be non-negative. **BN\_rshift1**() shifts *a* right by one and places the result in *r* (r=a/2).

For the shift functions, *r* and *a* may be the same variable.

## RETURN VALUES

**BN\_is\_bit\_set**() returns 1 if the bit is set, 0 otherwise.

All other functions return 1 for success, 0 on error. The error codes can be obtained by ERR\_get\_error(3).

## SEE ALSO

BN\_add(3), BN\_new(3), BN\_num\_bytes(3), BN\_set\_negative(3), BN\_zero(3)

## HISTORY

**BN\_set\_bit**(), **BN\_clear\_bit**(), **BN\_is\_bit\_set**(), **BN\_mask\_bits**(), **BN\_lshift**(), **BN\_lshift1**(), **BN\_rshift**(), and **BN\_rshift1**() first appeared in SSLeay 0.5.1 and have been available since OpenBSD 2.4.
