title: Java four bytes to binary 'bitmask'
body: <p>I'm trying to take four bytes from a binary file and turn them into a bit mask that represents a zero for data and a 1 for metadata.</p>
  
  <p>I'm assuming I need to convert them into an int by or'ing them together and then bit shift through that to determine if a bit position is set or not.</p>
  
  <p>I can't work out how to combine all four together to get a 32-bit mask that I can step though.</p>
  
  <pre><code>int mask = (((int)hbyte) &amp; 0xff) &lt;&lt; 8 | (((int)lbyte) &amp; 0xff);
  </code></pre>
  
  <p>That would combine two together (post by Laurence Gonsalves from another post) but I can't figure out the syntax to get four together.</p>
  
  <p>Or would this be case for an Enumset, which I'll admit I don't fully understand.</p>
  
  <p>Any advice would be appreciated.</p>
  
  <p>Thanks.</p>
  
  <p>Tony</p>
  
  <p>**Just to add another quick note to this, (I'm not sure if that's generally allowed so I apologise in advance if it's not), what is the best way of going through my newly created int and checking if a bit is set or not?</p>
  
  <p>Currently I'm using<code>if (((comboOfBytes &gt;&gt; bitmaskBit) &amp; 1) == 0)</code> but I don't know if that's the most elegant way of doing the check that I need.</p>
  
  <p>Also I'm still not entirely sure if I understand how shifting actually allows all 32 bits to be checked!</p>
  
  <p>Thanks again</p>