This is because, as stated in the documentation ,
The specified array must be of a compatible type. Only bool, int, and byte array types are supported.
So you can do something like this: (not verified)
private static long GetIntFromBitArray(BitArray bitArray) { var array = new byte[8]; bitArray.CopyTo(array, 0); return BitConverter.ToInt64(array, 0); }
Looking at the implementation of BitArray.CopyTo , it would be faster to copy the bit to int[] (and then build a long of its two halves), which could look something like this: (also not tested)
private static long GetIntFromBitArray(BitArray bitArray) { var array = new int[2]; bitArray.CopyTo(array, 0); return (uint)array[0] + ((long)(uint)array[1] << 32); }
Drops uint to prevent sign expansion.
source share