title: Java Bit Shifting, short conversion to byte
body: <p>I'm currently working a small project where I end up messing with byte, short value etc,
  and after some reading, I still don't understand some stuff, like what is "bit shifting", why do we use it, when do we need, and how does it work.</p>
  
  <p>Also, I found this function to convert short into byte:</p>
  
  <pre><code>private byte[] short2byte(short[] sData) {
      int shortArrsize = sData.length;
      byte[] bytes = new byte[shortArrsize * 2];
      for (int i = 0; i &lt; shortArrsize; i++) {
          bytes[i * 2] = (byte) (sData[i] &amp; 0x00FF);
          bytes[(i * 2) + 1] = (byte) (sData[i] &gt;&gt; 8);
          sData[i] = 0;
      }
      return bytes;
  
  }
  </code></pre>
  
  <p>I think I understand this function but my problem is that I'm not sure what these two lines are doing:</p>
  
  <pre><code>bytes[i * 2] = (byte) (sData[i] &amp; 0x00FF);
  bytes[(i * 2) + 1] = (byte) (sData[i] &gt;&gt; 8);
  </code></pre>
  
  <p>I think it has something to do with bit shifting, so can someone please explain what that means? If you have a link or good documentation regarding bytes, short, bit shifting etc, please include that if possible.</p>
  
  <p>Kind regards</p>