Re: Counting elements in a bitvector?

From: Karl Buchner (zerker@juno.com)
Date: 08/26/02


>I am using #define GUILD_FLAGS(ch) ((ch)->player_specials->saved.guild)

The following should test the number of bits set in a 32 bit bitvector.

for(numflags = 0, i = 0; i < 32; i++)
     if(GUILD_FLAGS(ch) & (1 << i))
          numflags++;

Just make sure you don't put anything extraneous in the same bitvector,
because that will be counted too.

You could probably replace GUILD_FLAGS(ch) & (1 << i) with
IS_SET(GUILD_FLAGS(ch), (1 << i)) for better readability.

Blaize




________________________________________________________________
GET INTERNET ACCESS FROM JUNO!
Juno offers FREE or PREMIUM Internet access for less!
Join Juno today!  For your FREE software, visit:
http://dl.www.juno.com/get/web/.

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/25/03 PDT