PHP Classes
elePHPant
Icontem

File: example.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.BitArray.php  >  Download  
File: example.BitArray.php
Role: Example script
Content type: text/plain
Description: example - usage file (setup BitArray, add/edit values)
Class: Bit Array
Manipulate compact arrays of bit values
Author: By
Last change: wrong package-name fixed
Date: 11 years ago
Size: 1,915 bytes
 

Contents

Class file image Download
<?php

   
/**
    * $RCSfile: example.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 BitArray-Class
    *
    **/
   
   
header("Content-Type: text/plain");
    include_once(
"lib.BitArray.php");
   
    function
PrintValues($myList, $myWidth) {
       
$ln = 0;
        for(
$i=0;$i<=(sizeof($myList)-1); $i++) {
            if(
$myList[$i])
                echo
"true";
            else
                echo
"false";
            echo
"\t";
           
$ln++;
            if(
$ln == $myWidth) {
               
$ln = 0;
                echo
"\n";
            }
        }
        echo
"\n";
    }
   
   
// create new BitArrays
   
$myBA1 = new BitArray(4);
   
$myBA2 = new BitArray(32);
   
$myBA3 = new BitArray(10);
       
   
// set a BA1 value to true
   
$myBA1->set(3,true);
   
   
// set all values of BA2
   
$myBA2->setAll(true);
   
   
// set BitArray3 to get the settings (when loaded from database, e.g.)
   
$myBA3->setBitArray(598);
   
$myBA3->setAll(true);
   
   
   
   
/**
    * print-out values
    */
   
echo "\nBA1 values:\n";
   
PrintValues($myBA1->getAll(),8);
    echo
"Bits: ".$myBA1->BitString."\n";
    echo
"Decimal Value: ".$myBA1->getBitArray()."\n";

    echo
"\nBA2 values:\n";
   
PrintValues($myBA2->getAll(),8);
    echo
"Bits: ".$myBA2->BitString."\n";
    echo
"Decimal Value: ".$myBA2->getBitArray()."\n";
   
    echo
"\nBA3 values:\n";
   
PrintValues($myBA3->getAll(),8);
    echo
"Bits: ".$myBA3->BitString."\n";
    echo
"Decimal Value: ".$myBA3->getBitArray()."\n";
?>