title: Bitwise operation and type conversion error
body: <p>I am unpacking a <code>byte[] content</code> into a bunch of fields.  Most of it directly maps from field to type (eg 4 bytes = Uint32).  There are some that are fields packed into a byte.  eg 8 bools, or 2bits + 4 bits + bool + bool.  In the constructor below I try to parse the <code>content</code> into class properties.</p>
  
  <pre><code>public RFTagLost(byte[] content)
  {
      byte flags1;
      UInt16 flags2;
  
      int i = 0;
  
      GatewaySerial = BitConverter.ToUInt32(content, i);
      i += sizeof(UInt32);
  
      SerialNumber = BitConverter.ToUInt32(content, i);
      i += sizeof(UInt32);
  
      Token = BitConverter.ToUInt32(content, i);
      i += sizeof(UInt32);
  
      flags1 = content[i];
      i += sizeof(byte);
      // TODO parse flags
      GatewayMode = (byte)((flags1 &gt;&gt; 0) &amp; 3);            // 2 bits
      LinkType = (byte)((flags1 &gt;&gt; 2) &amp; 3);               // 2 bits
      Reserved = (byte)((flags1 &gt;&gt; 4) &amp; 15);              // 4 bits
  
      TagType = content[i];
      i += sizeof(byte);
  
      flags2 = BitConverter.ToUInt16(content, i);
      i += sizeof(UInt16);
      LastSeen = (UInt16)((flags2 &gt;&gt; 0) &amp; 32767);           // 15 bits
      LastSeenInMinutes = (bool)((flags2 &gt;&gt; 15) &amp; 1);     // 1 bit
  }           
  </code></pre>
  
  <p>I was having problems with the shift and mask operations returning an int.  I finally worked out that despite flag1 being a byte, bitwise was returning an int that was causing my assign to property to fail.  Same with flag2.</p>
  
  <p>Now my error is that </p>
  
  <blockquote>
    <p>Cannot convert type 'int' to 'bool'</p>
  </blockquote>
  
  <p>This is when trying to extract the last field.  It's the last bit in a UInt16</p>
  
  <p>Am I doing the right thing to extract these bit fields.  What do I do to make <code>bool LastSeenInMinutes</code> work?</p>