Location: PHPKode > scripts > Bit Array > bit-array/example.and.BitArray.php
<?php

	/**
	*	$RCSfile: example.and.BitArray.php,v $
	*	@author 	$Author: Cornelius Bolten $
	*	@version	$Revision: 1.2 $
	*	@package	BitArray
	*	
	*	@copyright
	*	The Initial Developer of the Original Code is Cornelius Bolten.
	*	Portions created by Cornelius Bolten are Copyright (C) 2004 by Cornelius Bolten.
	*	All Rights Reserved.	
	*	Usage is free for non-commercial work. see http://www.phpclasses.org/browse/package/1540.html
	*	for more information.
	*
	*	@see
	*  	Latest releases are available at http://www.phpclasses.org/browse/package/1540.html 
	*	For feedback, bug reports or enhancements please contact the author at 
	*	hide@address.com Thanks a lot!
	*
	*	@description
	*	This is a working example for and-comparison of two BitArrays
	*
	**/
	
	header("Content-Type: text/plain");
	include_once("lib.BitArray.php");
	
	function PrintValues($myList, $myWidth) {
		for($i=0;$i<=($myWidth-1); $i++) {
			if($myList[$i])
				echo "true";
			else
				echo "false";
			echo "\t";
		}
		echo "\n";
	}
	
	$myBA1	=	new BitArray(4);
	$myBA2	=	new BitArray(4);	
	
	$myBA1->set(0,false);
	$myBA1->set(1,false);
	$myBA1->set(2,true);
	$myBA1->set(3,true);
	
	$myBA2->set(0,false);
	$myBA2->set(1,true);
	$myBA2->set(2,false);
	$myBA2->set(3,true);
	
	echo "\nBA1 values:\n";
	PrintValues($myBA1->getAll(),4);
	echo "\nBA2 values:\n";
	PrintValues($myBA2->getAll(),4);
	
	echo "\nAND values:\n";
	$result	=	$myBA1->_and($myBA2);
	PrintValues($result,4);


?>
Return current item: Bit Array