System.Collections.BitArray.GetArrayLength C# (CSharp) Method

GetArrayLength() private static method

Used for conversion between different representations of bit array. Returns (n+(div-1))/div, rearranged to avoid arithmetic overflow. For example, in the bit to int case, the straightforward calc would be (n+31)/32, but that would cause overflow. So instead it's rearranged to ((n-1)/32) + 1, with special casing for 0. Usage: GetArrayLength(77, BitsPerInt32): returns how many ints must be allocated to store 77 bits.
private static GetArrayLength ( int n, int div ) : int
n int
div int use a conversion constant, e.g. BytesPerInt32 to get /// how many ints are required to store n bytes
return int
        private static int GetArrayLength(int n, int div)
        {
            Debug.Assert(div > 0, "GetArrayLength: div arg must be greater than 0");
            return n > 0 ? (((n - 1) / div) + 1) : 0;
        }

Usage Example

示例#1
0
        public BitArray Not()
        {
            int arrayLength = BitArray.GetArrayLength(this.m_length, 32);

            for (int i = 0; i < arrayLength; i++)
            {
                this.m_array[i] = ~this.m_array[i];
            }
            this._version++;
            return(this);
        }
All Usage Examples Of System.Collections.BitArray::GetArrayLength