How can I convert BitArray to single int?
How can I convert BitArray to a single int ? 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]; } private int getIntFromBitArray(BitArray bitArray) { int value = 0; for (int i = 0; i < bitArray.Count; i++) { if (bitArray[i]) value += Convert.ToInt16(Math.Pow(2, i)); } return value; } This version: works for up to 64 bits doesn't rely on knowledge of BitArray implementation details doesn't needlessly allocate memory doesn't