How can I convert BitArray to single int?
问题 How can I convert BitArray to a single int ? 回答1: 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]; } 回答2: 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; } 回答3: This version: works for up