Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!samsung!uakari.primate.wisc.edu!caesar.cs.montana.edu!ogicse!decwrl!ucbvax!hplabs!hpda!hpwala!hpavla!gary From: gary@hpavla.AVO.HP.COM (Gary Jackoway) Newsgroups: comp.lang.c Subject: Re: array of bits field Message-ID: <9130003@hpavla.AVO.HP.COM> Date: 15 Feb 90 16:34:26 GMT References: <1990Feb12.182517.10921@cubmol.bio.columbia.edu> Organization: Hewlett-Packard Avondale Division Lines: 23 > 1. Define the 16 values as an unsigned int, and use bit manipulation to > access the individual bits. > > i.e., value & 0x0001 (or 1) represents the value in bit 1 of "value" > value &= 0x0040 (or 128) sets the value in bit 7 of "value" to 1 > value |= ~0x0080 (or 128) sets the value in bit 8 of "value" to 0 I think the &= should be |=, and vice versa. You can define macros: #define TESTBIT(value,bit) (value & (1<>bit & 1) which always gives a 0 or 1 result. Equivalent would be #define TESTBIT(value,bit) !!(value & (1<