Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h1>Bitwise Operator</h1> <p>What is a bit? A bit is a representation of 1 or 0. Basically OFF(0) and ON(1)</p> <p>What is a byte? A byte is made up of 8 bits and the highest value of a byte is 255, which would mean every bit is set. We will look at why a byte's maximum value is 255.</p> <pre><code>------------------------------------------- | 1 Byte ( 8 bits ) | ------------------------------------------- |Place Value | 128| 64| 32| 16| 8| 4| 2| 1| ------------------------------------------- </code></pre> <p>This representation of 1 Byte</p> <p>1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 = 255 (1 Byte) </p> <h1>A few examples for better understanding</h1> <h2>The "AND" operator: <code>&</code></h2> <pre><code>$a = 9; $b = 10; echo $a &amp; $b; </code></pre> <p>This would output the number 8. Why? Well let's see using our table example.</p> <pre><code>------------------------------------------- | 1 Byte ( 8 bits ) | ------------------------------------------- |Place Value | 128| 64| 32| 16| 8| 4| 2| 1| ------------------------------------------- | $a | 0| 0| 0| 0| 1| 0| 0| 1| ------------------------------------------- | $b | 0| 0| 0| 0| 1| 0| 1| 0| ------------------------------------------- | &amp; | 0| 0| 0| 0| 1| 0| 0| 0| ------------------------------------------- </code></pre> <p>So you can see from the table the only bit they share together is the 8 bit.</p> <p><strong>Second example</strong></p> <pre><code>$a = 36; $b = 103; echo $a &amp; $b; // This would output the number 36. $a = 00100100 $b = 01100111 </code></pre> <p>The two shared bits are 32 and 4, which when added together return 36.</p> <h2>The "Or" operator: <code>|</code></h2> <pre><code>$a = 9; $b = 10; echo $a | $b; </code></pre> <p>This would output the number 11. Why?</p> <pre><code>------------------------------------------- | 1 Byte ( 8 bits ) | ------------------------------------------- |Place Value | 128| 64| 32| 16| 8| 4| 2| 1| ------------------------------------------- | $a | 0| 0| 0| 0| 1| 0| 0| 1| ------------------------------------------- | $b | 0| 0| 0| 0| 1| 0| 1| 0| ------------------------------------------- | | | 0| 0| 0| 0| 1| 0| 1| 1| ------------------------------------------- </code></pre> <p>You will notice that we have 3 bits set, in the 8, 2, and 1 columns. Add those up: 8+2+1=11.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload