本文整理汇总了C#中System.Collections.BitArray.OfType方法的典型用法代码示例。如果您正苦于以下问题:C# BitArray.OfType方法的具体用法?C# BitArray.OfType怎么用?C# BitArray.OfType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.BitArray
的用法示例。
在下文中一共展示了BitArray.OfType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Substring
private static BitArray Substring(BitArray input, int from, int count)
{
return new BitArray(input.OfType<bool>().Skip(from).Take(count).ToArray());
}
示例2: Write
public void Write(byte[] bytes, int bitCount)
{
bytes = SwapEndianBytes(bytes);
BitArray array = new BitArray(bytes);
values.InsertRange(Position, array.OfType<bool>().Take(bitCount));
_Position += bitCount;
}
示例3: SaveBitSet
/// <summary>
/// Save bit array as bit set.
/// </summary>
/// <param name="bitArray">The bit array object.</param>
/// <param name="writer">The writer object.</param>
/// <returns>Bytes writen.</returns>
private static int SaveBitSet(BitArray bitArray, BinaryWriter writer)
{
int bytesWritten = 0;
writer.Write((int)SetType.BitSet);
writer.Write((int)bitArray.Length); // size
writer.Write((int)bitArray.OfType<bool>().Count(x => x)); // size
bytesWritten += sizeof(int) * 3;
// ((_unitSet.Length + 31) >> 5) * 4
// calculate the number of bytes to allocate to save
// the bit set data. the data is INT (4 bytes) aligned
byte[] data = new byte[((bitArray.Length + 31) >> 5) * 4];
bitArray.CopyTo(data, 0);
writer.Write(data, 0, data.Length);
bytesWritten += data.Length;
return bytesWritten;
}
示例4: SaveIndexSet
/// <summary>
/// Save bit array as index set.
/// </summary>
/// <param name="bitArray">The bit array object.</param>
/// <param name="writer">The writer object.</param>
/// <returns>Bytes writen.</returns>
private static int SaveIndexSet(BitArray bitArray, BinaryWriter writer)
{
int bytesWritten = 0;
writer.Write((int)SetType.IndexSet);
writer.Write((int)bitArray.OfType<bool>().Count(x => x));
bytesWritten += sizeof(int) * 2;
for (int i = 0; i < bitArray.Length; i++)
{
if (bitArray[i])
{
writer.Write(i);
bytesWritten += sizeof(int);
}
}
return bytesWritten;
}
示例5: ToIntegers
public static int[] ToIntegers(BitArray bits)
{
return
bits
.OfType<bool>()
.Select((v, i) => new
{
Group = i / 11,
Value = v ? 1 << (10 - (i % 11)) : 0
})
.GroupBy(_ => _.Group, _ => _.Value)
.Select(g => g.Sum())
.ToArray();
}