bitstostring.php

Go to the documentation of this file.
00001 <?php
00019 function bitsToString($type, $bits, $lookup, $joinString=', ', $useAnd=false)
00020 {
00021     //This is expensive if we are doing it lots of times, so a local per exec cache is appropriate
00022     static $cache;
00023     if($cache == null)
00024         $cache = array();
00025 
00026     //Init the cache array for this type
00027     if(!isset($cache[$type]))
00028         $cache[$type][0] = '(None)';
00029 
00030     if(!isset($cache[$type][$bits]))
00031     {
00032         $current = 1;
00033         $words = array();
00034         $count = 0;
00035         $last = '';
00036         
00037         while($current <= $bits)
00038         {
00039             if($current & $bits)
00040                 if(isset($lookup[$current]))
00041                     $words[] = $lookup[$current];
00042 
00043             $current = pow(2, ++$count);
00044         }
00045         
00046         if($useAnd === true)
00047         {
00048             $last = array_pop($words);
00049             $last = ((count($words) == 0) ? ('') : (' and ')) . $last;                
00050         }
00051         
00052         $result = $cache[$type][$bits] = implode($joinString, $words) . $last;
00053         
00054     }
00055     else
00056         $result = $cache[$type][$bits];
00057 
00058     return $result;
00059 }
00060 ?>

Generated on Wed Oct 25 03:13:32 2006 for LFSWorldParsingProviderFramework by  doxygen 1.4.6