note 31675 deleted from language.operators.bitwise by sniper

From: Date: Mon, 13 Oct 2003 00:13:32 +0000
Subject: note 31675 deleted from language.operators.bitwise by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-58414@lists.php.net to get a copy of this message
Note Submitter: ktulu@csionline.net ---- A previous comment posted a function flags2array. However, I noticed with this that the indexes of the array are opposite of what you would expect... ie: flags2array(175) = bits[0] = 1 bits[1] = 0 bits[2] = 1 bits[3] = 0 bits[4] = 1 bits[5] = 1 bits[6] = 1 bits[7] = 1 But 175 = 1 + 2 + 4 + 8 + 32 + 128 = 2^0 + 2^1 + etc... The indexes of the bits array do NOT correspond to the power of 2, the are equal to 7-power (I think)... So I modified the function to the following: function flags2array($dec) { $bits= Array(); $bin = decbin($dec); for ($i=0; $i<strlen($bin); $i++) $bits[strlen($bin)-$i-1] = $bin{$i}; return $bits; }

« previous php.notes (#58414) next »