Bump actions/upload-artifacts version
[libtommath.git] / mp_count_bits.c
blob52b463d46130543b8ce40e5d8452243faa1116ea
1 #include "tommath_private.h"
2 #ifdef MP_COUNT_BITS_C
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */
4 /* SPDX-License-Identifier: Unlicense */
6 /* returns the number of bits in an int */
7 int mp_count_bits(const mp_int *a)
9 int r;
10 mp_digit q;
12 /* shortcut */
13 if (mp_iszero(a)) {
14 return 0;
17 /* get number of digits and add that */
18 r = (a->used - 1) * MP_DIGIT_BIT;
20 /* take the last digit and count the bits in it */
21 q = a->dp[a->used - 1];
22 while (q > 0u) {
23 ++r;
24 q >>= 1u;
26 return r;
28 #endif