ARM Shanghai IoT Team (Internal) / newMiniTLS-GPL

Fork of MiniTLS-GPL by Donatien Garnier

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers fp_count_bits.c Source File

fp_count_bits.c

00001 /* TomsFastMath, a fast ISO C bignum library.
00002  * 
00003  * This project is meant to fill in where LibTomMath
00004  * falls short.  That is speed ;-)
00005  *
00006  * This project is public domain and free for all purposes.
00007  * 
00008  * Tom St Denis, tomstdenis@gmail.com
00009  */
00010 #include <tfm.h>
00011 
00012 int fp_count_bits (fp_int * a)
00013 {
00014   int     r;
00015   fp_digit q;
00016 
00017   /* shortcut */
00018   if (a->used == 0) {
00019     return 0;
00020   }
00021 
00022   /* get number of digits and add that */
00023   r = (a->used - 1) * DIGIT_BIT;
00024 
00025   /* take the last digit and count the bits in it */
00026   q = a->dp[a->used - 1];
00027   while (q > ((fp_digit) 0)) {
00028     ++r;
00029     q >>= ((fp_digit) 1);
00030   }
00031   return r;
00032 }
00033 
00034 /* $Source: /cvs/libtom/tomsfastmath/src/bit/fp_count_bits.c,v $ */
00035 /* $Revision: 1.1 $ */
00036 /* $Date: 2006/12/31 21:25:53 $ */