Re: [Circle] Bitvector Explanation please

From: Christopher M. Ryan (drizzt@visi.net)
Date: 11/28/96


> G'Day All,
> 	  i've read the docs, but i'm still unfamiliar with bitvectors and what
> they do. i know how to impleement them, but I'm not sure how to use them
in
> the game.
> For example. I had this
> #define open 0
> #define closed 1
> #define locked 2
> #define pickproof 3
> #define secret_closed 4
> #define secret_locked 5
> #define secret_pickproof 6
> 
> and i was told i don't nned 5 and 6 cause 4 already 'encompasses' them.
> This is why I'm confussed, so can someone quickly explain them please
> *blush*
> 
> Thanks as always.
> 
> 		jussy
	Lets see... Bitvectors? Well this is kinda easy. think of it like this, if
you have a byte (8 bits) 00000000 this would be zero (no affects).

IS_DOOR	(1 << 0)	/* 00000001 */
IS_CLOSED	(1 << 1)	/* 00000010 */
IS_LOCKED	(1 << 2)	/* 00000100 */
/* note that these are all powers of two. */

If you notice each affect has only one (1) on bit unique to the others.
Therefore you can combime the affects to get several.

00000011	/* actual value... IS_DOOR and IS_CLOSED */

The above is made up of doing bitwise operations on the two affects to
create one affect of the combination, but, due to the way the bits are
stored you can do bitwaise operations to extract the bits and see if and
affect is applied or not without changin everything.

	Did that make any sense? I hope so. well Hope this explained it. :)
Later all! I guess i could say happy thanksgiving but it is kinda late :)
any ways happy holidays.

Christopher M. Ryan
drizzt@visi.net
http://www.visi.net/~drizzt/index.html
http://www.visi.net/~drizzt/quake/index.html


+-----------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
|   http://cspo.queensu.ca/~fletcher/Circle/list_faq.html   |
+-----------------------------------------------------------+



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