2 * UCW Library -- Counting bits in bitarray
4 * (c) 2012 Pavel Charvat <pchar@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
11 #include <ucw/bitops.h>
12 #include <ucw/bitarray.h>
14 uns bit_array_count_bits(bitarray_t a, uns n)
17 n = BIT_ARRAY_WORDS(n);
31 bitarray_t a = alloca(BIT_ARRAY_BYTES(sizeof(buf)));
34 if (!fgets(buf, sizeof(buf), stdin))
37 for (n = 0; buf[n] == '0' || buf[n] == '1'; n++);
39 for (uns i = 0; i < n; i++)
42 printf("%u\n", bit_array_count_bits(a, n));