Newsgroups: comp.os.msdos.djgpp Date: Mon, 21 Jul 1997 12:54:09 -0400 (EDT) From: Insomnia Reply-To: Insomnia To: Isaac Waldron cc: djgpp AT delorie DOT com Subject: Re: Bit-wise compare In-Reply-To: <33D36DA3.7EB2@lr.net> Message-ID: References: <33D36DA3 DOT 7EB2 AT lr DOT net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk First: The "&&" operator is for logical "and" (ie if (a>1 && b>2), not for bitwise anding. Try the following instead: /**** int has_item(int equip, int item) { return (equip & item); } /**** This will return 0 if item is not in equip, or non-zero (eg: true) if it is. Make sure that all of your items' bits don't step on each other unless they are mutually exclusive. For example you could have. /**** #define BIG_ROCK 1 // Could also use const ints #define HELMET 2 #define A_LITTLE_FOOD 4 #define SOME_FOOD 12 #define A_LOT_OF_FOOD 28 #define STILLETTO 32 /**** In this example, BIG_ROCK uses bit 0, HELMET uses bit 1, FOOD uses bits 2, 3 and 4, and STILLETTO uses bit 5. (Note that if you ask if a character with SOME_FOOD, or A_LOT_OF_FOOD, has A_LITTLE_FOOD, it will return true, etc...). Hope this helps. --Insomnia --Sleep is for the weak!