delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/21/10:10:29

Message-ID: <33D36DA3.7EB2@lr.net>
Date: Mon, 21 Jul 1997 10:09:39 -0400
From: Isaac Waldron <waldroni AT lr DOT net>
Reply-To: waldroni AT lr DOT net
Organization: The Computer Nerd
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Bit-wise compare

I am working on an RPG computer game, and I was wondering if it is
possible to do the following:

#include <iostream.h>

const int WEAPON_SWORD_1 = 1;
const int WEAPON_SWORD_2 = 2;

int has_item(int a, int b)
{
	if (a && b)
	{
		return 1;
	}
	else
	{
		return 0;
	};
};

int main()
{
	int a, b, c, d;
	a = a || WEAPON_SWORD_1;
	b = b || WEAPON_SWORD_2;
	c = has_item(b, WEAPON_SWORD_1);
	d = has_item(a, WEAPON_SWORD_2);
	cout << d << " " << c;
	return 0;
};

What I want has_item to do is see if the bit that is set in b is also
set in a.  That way, I could use one variable to determine equipment on
the character.  I also replaced all the int's with float's, but that
didn't work.

Any help is appreciated,
-- 
-Begin Signature-
Isaac Waldron <waldroni AT lr DOT net> N1YZI
http://www.geocities.com/SiliconValley/Lakes/5703/home.html
-End Signature-

- Raw text -


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