title: Why do we use mask for cutting bytes?
body: <p>So I guess this one is pretty stupid but I can't figure the answer by myself.</p>
  
  <p>A few days ago I had to create a function that returns the strong byte of an unsigned integer. After a few researches on the web, I came up with this one:</p>
  
  <pre><code>fn strong_byte(num: u32) -&gt; u8 {
    ((num &gt;&gt; 24) &amp; 0xFF) as u8
  }
  </code></pre>
  
  <p>But after searching again for a while I also found this one:</p>
  
  <pre><code>fn strong_byte(num: u32) -&gt; u8 {
    (num &lt;&lt; 24 &gt;&gt; 24) as u8
  }
  </code></pre>
  
  <p>So I was wondering which form was the more performant? I tried to find benchmarks showing left shift vs bitmask performance, but didn't find anything...</p>
  
  <p>I know the first syntax is by far the most used, but I can't understand why the second is not... </p>