title: Bit Hack - Round off to multiple of 8
body: <p>can anyone please explain how this works  (asz + 7) &amp; ~7; It rounds off asz to the next higher multiple of 8.</p>
  
  <p>It is easy to see that ~7 produces 11111000 (8bit representation) and hence switches off the last 3 bits  ,thus any number which is produced is a multiple of 8.</p>
  
  <p>My question is how does adding asz to 7 before masking [edit] produce the next higher[end edit] multiple of 8 ? I tried writing it down on paper </p>
  
  <p>like :</p>
  
  <pre><code>1 + 7 = 8  = 1|000 (&amp; ~7) -&gt; 1000
  2 + 7 = 9  = 1|001 (&amp; ~7) -&gt; 1000
  3 + 7 = 10 = 1|010 (&amp; ~7) -&gt; 1000
  4 + 7 = 11 = 1|011 (&amp; ~7) -&gt; 1000
  5 + 7 = 12 = 1|100 (&amp; ~7) -&gt; 1000
  6 + 7 = 13 = 1|101 (&amp; ~7) -&gt; 1000
  7 + 7 = 14 = 1|110 (&amp; ~7) -&gt; 1000
  8 + 7 = 15 = 1|111 (&amp; ~7) -&gt; 1000
  </code></pre>
  
  <p>A pattern clearly seems to emerge which has been exploited .Can anyone please help me it out ?</p>
  
  <p>Thank You all for the answers.It helped confirm what I was thinking. I continued the writing the pattern above and when I crossed 10 , i could clearly see that the nos are promoted to the next "block of 8"  if I can say so.</p>
  
  <p>Thanks again.</p>