note 31675 added to language.operators.bitwise

From: Date: Wed, 30 Apr 2003 01:27:42 +0000
Subject: note 31675 added to language.operators.bitwise
Groups: php.notes 
Request: Send a blank email to php-notes+get-47269@lists.php.net to get a copy of this message
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; } -- http://www.php.net/manual/en/language.operators.bitwise.php http://master.php.net/manage/user-notes.php?action=edit+31675 http://master.php.net/manage/user-notes.php?action=delete+31675 http://master.php.net/manage/user-notes.php?action=reject+31675

« previous php.notes (#47269) next »