User permissions binary/decimal confusion after unexpected behavior
<p>First of all I do not understand why some people are using binary number and powers of two for permissions. Is it because they stand for true/false with 1/0 from backwards relation?</p>

<p>Ex: <code>1010 means false, true, false, true</code> ?</p>

<p>My question is following. <code>15</code> in decimal is same as <code>1111</code> in binary, BUT:</p>

<pre><code>DEFINE ('READ',1);
DEFINE ('WRITE',2);
DEFINE ('EDIT',4);
DEFINE ('DELETE',8);

$current = 15;

if ($current &amp; READ) print("can read &lt;br /&gt;");
if ($current &amp; WRITE) print("can write &lt;br /&gt;");
if ($current &amp; EDIT) print("can edit &lt;br /&gt;");
if ($current &amp; DELETE) print("can delete &lt;br /&gt;");
</code></pre>

<p>This outputs that all permissions are allowed, as I expect. However, if I change 15 with <code>1111</code> then it shows only 3 of them that are allowed not all four (<code>delete</code> permission comes as invalid):</p>

<pre><code>DEFINE ('READ',1);
DEFINE ('WRITE',2);
DEFINE ('EDIT',4);
DEFINE ('DELETE',8);

$current = 1111;

if ($current &amp; READ) print("can read &lt;br /&gt;");
if ($current &amp; WRITE) print("can write &lt;br /&gt;");
if ($current &amp; EDIT) print("can edit &lt;br /&gt;");
if ($current &amp; DELETE) print("can delete &lt;br /&gt;");
</code></pre>

<p>Is not it strange? Do I understand it incorrectly? I need some help to understand this. Should I store permissions as decimals or binaries in db?</p>
