How can I convert BitArray to single int?

Vlad Omelyanchuk picture Vlad Omelyanchuk · Mar 12, 2011 · Viewed 48.9k times · Source

How can I convert BitArray to a single int?

Answer

Luca Fagioli picture Luca Fagioli · Mar 12, 2011
private int getIntFromBitArray(BitArray bitArray)
{

    if (bitArray.Length > 32)
        throw new ArgumentException("Argument length shall be at most 32 bits.");

    int[] array = new int[1];
    bitArray.CopyTo(array, 0);
    return array[0];

}