delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/21/13:09:57

Newsgroups: comp.os.msdos.djgpp
Date: Mon, 21 Jul 1997 12:54:09 -0400 (EDT)
From: Insomnia <insomnia AT degobah DOT core DOT binghamton DOT edu>
Reply-To: Insomnia <insomnia AT degobah DOT core DOT binghamton DOT edu>
To: Isaac Waldron <waldroni AT lr DOT net>
cc: djgpp AT delorie DOT com
Subject: Re: Bit-wise compare
In-Reply-To: <33D36DA3.7EB2@lr.net>
Message-ID: <Pine.SUN.3.93.970721123529.8786C-100000@degobah>
References: <33D36DA3 DOT 7EB2 AT lr DOT net>
MIME-Version: 1.0

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!


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019