Re: Code thats out there!

From: Chaotic (chaotic@eskimo.com)
Date: 06/16/95


On Fri, 16 Jun 1995, Anthony Spataro wrote:

> On Thu, 15 Jun 1995, Giao H Phan wrote:
> > on wizbits, as an aside to hex, have you guys started using that idea 
> > whereby you could stuff like 80 bits into one var? i heard some bits and 
> > .... [snip]

>                            ...... [snip]   You could also just use an 
> array of long[2] and write an intelligent function-like macro to figure 
> out which long to compare with, but you'll run smack up against word 
> ordering on different machines, as well as the cases where you need to 
> check bits from both elements of the array.

an easier, more portable method that i have used in the past is to use a 
char[] array.  ordering is no problem, and macros for setting bits, 
testing bits, clearing bits, etc., actually expand out to very few bytes 
of code.

the other great thing is that you can make it as large as you need.  need 
120 bits?  go for it!  i have, in the past, used arrays as large as 1K to 
get 8K worth of bits (obviously not in a mud, but a data application).

some quick examples (b=bit no., a=char array)

#define SETBIT(b,a)  (a[(b>>3)]|=(1<<(b&7)))   // set a bit
#define CLRBIT(b,a)  (a[(b>>3)]&=~(1<<(b&7)))  // clear a bit
#define TSTBIT(b,a)  (a[(b>>3)]&(1<<(b&7)))    // test for bit set
#define TGLBIT(b,a)  (a[(b>>3)]^(1<<(b&7)))    // toggle bit state

lauren



This archive was generated by hypermail 2b30 : 12/18/00 PST