Re: algorythm question

From: Date: Sat, 21 Sep 2002 15:25:41 +0000
Subject: Re: algorythm question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-117100@lists.php.net to get a copy of this message
On Sun, 22 Sep 2002 01:10, you wrote: > consider there are categories and these have IDs like > below: > 1, 2, 4, 8, 16, 32, 64... > > if some data belongs to more than 1 category for > exemple 4 and 32, its category ID will be 36, the sum > of cat. IDs. > i guess this is used widely in programming. so, how > can i resolve the original IDs. i mean what kind of > script can tell me what+what1+what2...whatN = 79? 1. To do that you should 'or' the categories when the ID's are to be in more than one category, not add them eg $category = $cat1 | $cat2; 2. To extract the categories within a compounded category use the 'and' operator '&' eg for ($mask=1; $mask <= 64; /*or whatever*/ $mask *= 2; ) { if ( $mask & $category ) { print "Yes $mask is in $category\n"; } }

« previous php.general (#117100) next »