Path: utzoo!attcan!uunet!microsoft!peted From: peted@microsoft.UUCP (Peter DUNIHO) Newsgroups: comp.lang.c Subject: Re: more that 32 flag array testing Summary: Bit fields bigger than 32 bits... Keywords: boolean,testing,bits Message-ID: <58179@microsoft.UUCP> Date: 12 Oct 90 03:18:50 GMT References: <1990Oct8.165154.26747@vitro.uucp> Distribution: comp Organization: Microsoft Corp., Redmond WA Lines: 31 In article <1990Oct8.165154.26747@vitro.uucp>, fsb@vitro.uucp (Steve Brailsford) writes: > problem I have with finding a good efficient, fast storage > mechanism for storing 100 boolean flags. Basically, I have > I couldn't think of a way to use 100 bits worth of storage > without it getting really hairy computationally. If I use > enums and test some location, locations are maxed at 32 bits. > How could I find if the 33 bit was set without having some > array of longs. The problem is even more complex in the fact > > Steve Brailsford Usenet: uunet!media!vitro!fsb Well, I think it would be okay to use an array of longs (or chars, if you want to minimize wasted space). Just define a macro like this: #define BIT_SET(bitfield,bit) (bitfield[bit/sizeof(*bitfield)] & \ (0x01 << (bit % sizeof(*bitfield)))) Just off the top of my head (which often times gets me the wrong answers :) ), I think that oughta work with a minimum of trouble to you. It's easily modifed to handle larger bitfields - or, more precisely, it doesn't need to be modifed to handle larger bitfields. The data types would be unsigned long bitfield[4] /* or */ unsigned char bitfield[13]; and int bit; This could be tweaked as you need it to be...the macro will return the value of the bit (well, set will be non-zero, unset will be zero). Other macros to set the bits or do whatever else are similar. Pete D.