title: How do I get the "left-most 128 bits of a byte array"?
body: <p>So I'm reading through the JWT token format as described at Open ID Connect and one of the fields (at_hash) says that it is the left-most 128 bits of hash made from the oauth access token. So what I've done is taken the token, hashed it, and then attempted to pull the "left-most" 128 bits out, but I feel like I'm doing this all wrong; it feels kludgy.</p>
  
  <p>So I guess my questions are:</p>
  
  <ul>
  <li>Is this even remoted correct?</li>
  <li><p>Is there a better, more accurate way to do this?</p>
  
  <pre><code>private byte[] GetFirst128(byte[] hash)
  {
      var bitArray = new BitArray(hash);
      var left128 = new List&lt;bool&gt;();
      for (var i = 0; i &lt; 128; i++)
      {
          left128.Add(bitArray[i]);
      }
  
      // convert back to byte[]
      var r = Array.ConvertAll(left128.ToArray(),
          bit =&gt; bit
              ? (byte) 1
              : (byte) 0);
  
      return r;
  }
  </code></pre></li>
  </ul>