title: Any benefit in using WEXITSTATUS macro in C over division by 256 on exit() status?
body: <p>I was doing an exercise for university where I had to return a value with exit, that value was actually a count of something. This could be above 255 (which exit() can't handle) but the teacher suggested to use test data where the count could never go above that value.</p>
  
  <p>After all this, I needed to handle this count value, the exit status, I got this value in the main process by using waitpid(). To my surprise, if the child process returned 1, the "real" value in the main process was 256, 2 was 512 and so on...</p>
  
  <p>I needed to print this value so I simply divided it by 256 and it was done. However, if I use the WEXITSTATUS() macro, I'll also get this value the way I want it...</p>
  
  <p>I looked at C source code and this is what I found out:</p>
  
  <pre><code>#define __WEXITSTATUS(status) (((status) &amp; 0xff00) &gt;&gt; 8)
  </code></pre>
  
  <p>I understand what's happening here, for instance, 512 in binary is 10 0000 0000, shifting 8 o the right will give 00 0000 0010, which is 2 in decimal. What I don't understand in this macro is that &amp; operator and the fact that 0xff00 seems a random number (it probably isn't, where does it come from though?). What does this do exactly, why is there "&amp; 0xff00" in the macro? Wouldn't it work with out it?</p>
  
  <p>And the real question in this topic, is the same thing to call this macro in my code as dividing by 256?</p>