Question

I am using the BIGNUM library from OpenSSL and I need to do a calculation in an if statement as follows:

if (expo & 1)

I know for bit shifting there are functions. Is there a function corresponding to this kind of operation (where expo is a BIGNUM*)? If not, is there a way to carry this out?

Était-ce utile?

La solution

The function you are looking for is:

bool BN_is_bit_set( const BIGNUM *a, int n );

... it behaves exactly like the bitwise operator AND. For example, to see if the right-most bit is on I would call the function as follows:

bool is_set = BN_is_bit_set( ptr_my_bignum, 0x1 );

... notice my mask is 0x1 (which implies 1 in binary). More information on the BIGNUM library can be found here.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top