title: Are there any Bitwise Operator Laws?
body: <p>Thinking in terms of Algebraic laws, I was wondering if there are any official guide lines which exist in the realm of bit manipulations, similar to Algebra.</p>
  <p><strong>Algebraic Example</strong></p>
  <p><code>a - b =/= b - a</code></p>
  <p>Let <code>a = 7</code> and <code>b = 5</code></p>
  <ul>
  <li><code>a - b = 2</code></li>
  <li><code>b - a = -2</code></li>
  </ul>
  <p>Let <code>a = 10</code> and <code>b = 3</code></p>
  <ul>
  <li><code>a - b = 7</code></li>
  <li><code>b - a = -7</code></li>
  </ul>
  <p>Thus <code>if a &gt; b</code>, <code>b - a</code> will be the negative equivalent to <code>a - b</code>. Because of this, we <em>can</em> say <br /><br />
  <code>|a - b| = |b - a|</code>.</p>
  <p>Where <code>|x|</code> denotes the absolute value of <code>x</code>.</p>
  <p><strong>Bitwise Example</strong></p>
  <p><code>a | b =/= a + b</code></p>
  <pre><code>      00001010 = 10
    OR  00000101 = 5 
    -----------------
        00001111 = 15
  </code></pre>
  <p>Note the unsigned byte manipulation: <code>10 | 5 = 15</code>, which is synonymous with <code>10 + 5 = 15</code></p>
  <p>However, if both <code>a</code> and <code>b</code> equal 5 and we <code>OR</code> them, the result would be 5, because <code>a = b</code>, which means we're just comparing the same exact bits with each other, thus resulting in nothing new.</p>
  <p>Likewise, if <code>b = 7</code>, <code>a = 10</code> and we <code>OR</code> them we'll have 15. This is because</p>
  <pre><code>    00001010 = 10
   OR 00000111 = 7
   -----------------
      00001111 = 15
  </code></pre>
  <p>So, we can effectively conclude that <code>a | b =/= a + b</code>.</p>