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

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

 



another solution

$input = 13;
$bits = 4;

for ($i=0; $i<$bits; $i++)
    echo pow(2,$i) . ' - ' . ((pow(2,$i) & $input) ? 'set' : 'unset') .
'<BR>';

-Jeff Bennett

----- Original Message -----
From: "Jason C" <jasonconrads@yahoo.com>
To: <php-objects@yahoogroups.com>
Sent: Wednesday, May 14, 2003 10:12 AM
Subject: Re: [php-objects] Request for a BitMask function/class.


> 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>
>
>
>
>
> 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/
>
>


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Rent DVDs Online - Over 14,500 titles.
No Late Fees & Free Shipping.
Try Netflix for FREE!
http://us.click.yahoo.com/YoVfrB/XP.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