bn_mp_count_bits.cGo to the documentation of this file.00001 #include <tommath.h> 00002 #ifdef BN_MP_COUNT_BITS_C 00003 /* LibTomMath, multiple-precision integer library -- Tom St Denis 00004 * 00005 * LibTomMath is a library that provides multiple-precision 00006 * integer arithmetic as well as number theoretic functionality. 00007 * 00008 * The library was designed directly after the MPI library by 00009 * Michael Fromberger but has been written from scratch with 00010 * additional optimizations in place. 00011 * 00012 * The library is free for all purposes without any express 00013 * guarantee it works. 00014 * 00015 * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com 00016 */ 00017 00018 /* returns the number of bits in an int */ 00019 int 00020 mp_count_bits (mp_int * a) 00021 { 00022 int r; 00023 mp_digit q; 00024 00025 /* shortcut */ 00026 if (a->used == 0) { 00027 return 0; 00028 } 00029 00030 /* get number of digits and add that */ 00031 r = (a->used - 1) * DIGIT_BIT; 00032 00033 /* take the last digit and count the bits in it */ 00034 q = a->dp[a->used - 1]; 00035 while (q > ((mp_digit) 0)) { 00036 ++r; 00037 q >>= ((mp_digit) 1); 00038 } 00039 return r; 00040 } 00041 #endif 00042 00043 /* $Source: /cvsroot/tcl/libtommath/bn_mp_count_bits.c,v $ */ 00044 /* $Revision: 1.1.1.3 $ */ 00045 /* $Date: 2006/12/01 00:08:11 $ */
Generated on Wed Mar 12 12:18:24 2008 by 1.5.1 |