title: How to execute Bit logic with Math expressions in C# that return as a boolean result?
body: <p>I am converting legacy VB.NET code to C# and have stumbled across a bit logic expression that for the life of me cannot translate to C#.</p>
  <p>The VB.NET snippet below basically evaluates each math expression and based on the boolean result, it sets the array index to that boolean value.</p>
  <pre><code>    Public Function createBigEndianBitArray(ByVal bt() As Byte) As BitArray
      Dim boolAra() As Boolean
      Dim ba As BitArray
      Dim x As Integer, y As Integer
      Dim cur_index As Integer
      ' get the length of the byte array and multiply by 8 for the
      ' length of the boolean array
      ReDim boolAra((bt.Length * 8) - 1)
  
      cur_index = 0 ' boolean array index
  
      ' iterate through the byte array
      For x = 0 To bt.Length - 1
          ' iterate through each byte
          For y = 7 To 0 Step -1
              boolAra(cur_index) = bt(x) And 2 ^ y
              cur_index += 1
          Next
      Next
  
      ba = New BitArray(boolAra)
      Return ba
  End Function
  </code></pre>
  <p>In C#, online translator were completely hosed up and the only way I am able to even get it to compile is by wrapping both math expressions in a Convert.Boolean(). However, when i compare the output of both, they are vastly different results meaning the bit logic isn't working the same.</p>
  <pre><code>    public BitArray createBigEndianBitArray(byte[] bt)
      {
          bool[] boolAra;
          BitArray ba;
          int x;
          int y;
          int cur_index;
          // get the length of the byte array and multiply by 8 for the
          // length of the boolean array
          boolAra = new bool[(bt.Length * 8)];
  
          cur_index = 0; // boolean array index
  
          // iterate through the byte array
          for (x = 0; x &lt;= bt.Length - 1; x++)
          {
              // iterate through each byte
              for (y = 7; y &gt;= 0; y += -1)
              {
                  boolAra[cur_index] = Convert.ToBoolean(bt[x]) &amp; Convert.ToBoolean(Math.Pow(2, y));
                  cur_index += 1;
              }
          }
  
          ba = new BitArray(boolAra);
          return ba;
      }
  </code></pre>