Login   Register  
PHP Classes
elePHPant
Icontem

File: example.and.BitArray.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Cornelius Bolten  >  Bit Array  >  example.and.BitArray.php  >  Download  
File: example.and.BitArray.php
Role: Example script
Content type: text/plain
Description: and-example script
Class: Bit Array
Manipulate compact arrays of bit values
Author: By
Last change: wrong package-name fixed
Date: 2004-03-19 01:56
Size: 1,471 bytes
 

Contents

Class file image Download
<?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 
    *    c.bolten@grafiknews.de. 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);


?>