Re: [php-objects] Request for a BitMask function/class.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Probably not the most efficient way, but this seems to do what you
asked...

$input = 13;

$str = strrev( (string)decbin( $input ) );

for( $i = 0; $i < strlen( $str ); $i++ )
{
    $var = pow( 2, $i );
    $output[$var] = ( $str[$i] == 1 ) ? 'set' : 'unset';
}

print_r( $output );

Produces:
Array
(
    [1] => set
    [2] => unset
    [4] => set
    [8] => set
)

Jason.

On Tue, 2003-05-13 at 10:11, sfpk wrote:
> I am looking for a function that can handle a variable
> and extract (via a bitmask, as an array) the seperate
> flags (and put them in an array, or each in their own
> variable). Something like:
> 
> Input:
> $CollectedSettingsString = "13";
> 
> Call:
> getIndividualVars($CollectedSettings);
> 
> Output:
> $SetArgumentsArray : 1 = set, 2 = unset, 4 = set, 8 = set
> 
> 
> 
> 
> Look here for Free PHP Classes of objects:
> http://phpclasses.UpperDesign.com/
> To unsubscribe from this group, send an email to:
> php-objects-unsubscribe@egroups.com
> 
>  
> 
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
-- 
Jason C <jasonconrads@yahoo.com>



------------------------ Yahoo! Groups Sponsor ---------------------~-->
Rent DVDs from home.
Over 14,500 titles. Free Shipping
& No Late Fees. Try Netflix for FREE!
http://us.click.yahoo.com/BVVfoB/hP.FAA/uetFAA/saFolB/TM
---------------------------------------------------------------------~->

Look here for Free PHP Classes of objects:
http://phpclasses.UpperDesign.com/
To unsubscribe from this group, send an email to:
php-objects-unsubscribe@egroups.com

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux