本文整理汇总了C#中System.Collections.BitArray类的典型用法代码示例。如果您正苦于以下问题:C# BitArray类的具体用法?C# BitArray怎么用?C# BitArray使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BitArray类属于System.Collections命名空间,在下文中一共展示了BitArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AsyncResult
internal AsyncResult(string message, int ftpCode, int result)
{
m_result = new BitArray(3);
m_message = message;
m_ftpResponse = ftpCode;
m_result[result] = true;
}
示例2: MakeADTree
private ADNode MakeADTree(int i, BitArray recordNums, int depth, Varset variables)
{
// since this is index i, there are (variableCount - i) remaining variables.
// therefore, it will have that many children
int count = 0;
for(int idx = 0; idx < recordNums.Count; idx++)
{
if (recordNums[idx])
{
count += 1;
}
}
ADNode adn = new ADNode(network.Size() - i, count);
// check if we should just use a leaf list
if (adn.Count < rMin)
{
BitArray leafList = new BitArray(recordNums);
adn.LeafList = leafList;
return adn;
}
// for each of the remaining variables
for (int j = i; j < network.Size(); j++)
{
// create a vary node
variables.Set(j, true);
Varset newVariables = new Varset(variables);
VaryNode child = MakeVaryNode(j, recordNums, depth, newVariables);
adn.SetChild(j - i, child);
}
return adn;
}
示例3: Mutate
/*
// It mutates the Chromosome
//
// @input probability is a double >=0 and <=100
*/
public bool Mutate(double probability)
{
if (probability < 0) probability = 0;
if (probability > 100) probability = 100;
bool isMutated = false;
for (int counter = 0; counter<nucleotideList.Count; counter++)
{
byte myByte = nucleotideList[counter];
//var bits = new BitArray(myByte);
var bits = new BitArray(new byte[] { myByte });
//Cycle for change the single bit of the DNA
for (int i = 0; i < bits.Length; i++)
{
Random r = new Random(Guid.NewGuid().GetHashCode());
if (r.NextDouble() < (probability / 100))
{
bits[i] = !bits[i]; //the mutation switch the bit
isMutated = true;
}
}
//From BitArray to Byte[]
byte[] ret = new byte[bits.Length / 8];
bits.CopyTo(ret, 0);
//Assigning the new Byte[] to the nucleotide
nucleotideList[counter] = ret[0];
}
return isMutated;
}
示例4: Setup
private void Setup()
{
// Fill Bit arrays
chka = new[] {
flag_0001,flag_0002,flag_0003,flag_0004,flag_0005,
flag_2237,flag_2238,flag_2239,
flag_0115,flag_0963, // Mewtwo
flag_0114,flag_0790, // Zygarde
flag_0285,flag_0286,flag_0287,flag_0288,flag_0289, // Statuettes
flag_0290,flag_0291,flag_0292,flag_0293,flag_0294, // Super Unlocks
flag_0675, // Chatelaine 50
flag_2546, // Pokedex
};
byte[] data = new byte[0x180];
Array.Copy(Main.SAV.Data, Main.SAV.EventFlag, data, 0, 0x180);
BitArray BitRegion = new BitArray(data);
BitRegion.CopyTo(flags, 0);
// Setup Event Constant Editor
CB_Stats.Items.Clear();
for (int i = 0; i < Constants.Length; i += 2)
{
CB_Stats.Items.Add($"0x{i.ToString("X3")}");
Constants[i / 2] = BitConverter.ToUInt16(Main.SAV.Data, Main.SAV.EventConst + i);
}
CB_Stats.SelectedIndex = 0;
// Populate Flags
setup = true;
popFlags();
}
示例5: CompleteGraph
public CompleteGraph(int n)
{
if (n <= 0)
throw new ArgumentOutOfRangeException("[CompleteGraph Constructor] Input size of CompleteGraph must be positive");
this.nodes = n;
this.edges = new BitArray(n * (n - 1) / 2);
}
示例6: GetBoolArrayFromByte
public static bool[] GetBoolArrayFromByte(byte[] bytes)
{
bool[] bools = new bool[bytes.Length * 8];
BitArray bits = new BitArray(bytes);
bits.CopyTo(bools, 0);
return bools;
}
示例7: SlabAllocator
public SlabAllocator(int pageSize, int pageCount)
{
_pageSize = pageSize;
_totalSize = pageCount * pageSize;
_allocationMap = new BitArray(pageCount);
}
示例8: DoPrevSetBit
internal virtual void DoPrevSetBit(BitArray a, LongBitSet b)
{
int aa = a.Count + Random().Next(100);
long bb = aa;
do
{
//aa = a.PrevSetBit(aa-1);
aa--;
while ((aa >= 0) && (!a.SafeGet(aa)))
{
aa--;
}
if (b.Length() == 0)
{
bb = -1;
}
else if (bb > b.Length() - 1)
{
bb = b.PrevSetBit(b.Length() - 1);
}
else if (bb < 1)
{
bb = -1;
}
else
{
bb = bb >= 1 ? b.PrevSetBit(bb - 1) : -1;
}
Assert.AreEqual(aa, bb);
} while (aa >= 0);
}
示例9: GetBitmapData
/// <summary>
/// get the B&W 1BPP bitmap for a bmp file
/// </summary>
/// <param name="bmpFileName">
/// </param>
/// <returns>
/// </returns>
private static BitmapDotData GetBitmapData(string bmpFileName)
{
Image img = new Bitmap(bmpFileName);
using (var bitmap = new Bitmap(img))// (Bitmap)Bitmap.FromFile(bmpFileName))
{
var threshold = 127;
var index = 0;
var dimensions = bitmap.Width * bitmap.Height;
var dots = new BitArray(dimensions);
for (var y = 0; y < bitmap.Height; y++)
{
for (var x = 0; x < bitmap.Width; x++)
{
var color = bitmap.GetPixel(x, y);
var luminance = (int)(color.R * 0.3 + color.G * 0.59 + color.B * 0.11);
dots[index] = (luminance < threshold);
index++;
}
}
return new BitmapDotData()
{
Dots = dots,
Height = bitmap.Height,
Width = bitmap.Width
};
}
}
示例10: ArrayFieldOfView
public ArrayFieldOfView(IFovBoard<IHex> board)
{
_isOnboard = h => board.IsOnboard(h);
_fovBacking = new BitArray[board.MapSizeHexes.Width];
for (var i = 0; i < board.MapSizeHexes.Width; i++)
_fovBacking[i] = new BitArray(board.MapSizeHexes.Height);
}
示例11: TM1638ButtonsMessageReader
private void TM1638ButtonsMessageReader(IList<int> messageData)
{
int readPos = 1;
for (int u = 1; u <= this.numberUnits; u++)
{
if (this.tm1640Units[u - 1])
{
continue;
}
this.buttonsRead = messageData[readPos++];
if (this.buttonsRead != -1)
{
this.butByte[0] = Convert.ToByte(this.buttonsRead);
this.buttons = new BitArray(this.butByte);
for (var i = 0; i < Constants.NumberButtonsOnTm1638; i++)
{
if (this.buttons[i])
{
if (this.ButtonPress == null) throw new ArgumentNullException();
ButtonPressEventHandler temp = this.ButtonPress;
if (temp != null)
{
temp(u, i+1);
}
}
}
}
}
}
示例12: GetCombines
static IList<string> GetCombines(string str)
{
var result = new List<string>();
var arr = str.Split(',');
var numItem = arr.Length;
for (int i = 1; i <= Math.Pow(2, numItem); i++)
{
string temp = null;
BitArray b = new BitArray(new int[] { i });
for (int j = 0; j < numItem; j++)
{
if (b[j])
{
if (temp != null)
{
temp += ",";
}
temp += arr[j];
}
}
if (!string.IsNullOrEmpty(temp))
{
result.Add(temp);
}
}
return result;
}
示例13: GetByteArrayFromBool
/// <summary>
/// Get bytes array from Boolean values.
/// </summary>
/// <param name = "array">Array to be packed</param>
/// <returns>Bytes array</returns>
public static byte[] GetByteArrayFromBool(bool[] array)
{
BitArray b = new BitArray(array);
byte[] bytesArr = new byte[array.Length / 8];
b.CopyTo(bytesArr, 0);
return bytesArr;
}
示例14: WriteBitArray
private static void WriteBitArray(ObjectWriter writer, BitArray bitArray)
{
// Our serialization format doesn't round-trip bit arrays of non-byte lengths
Contract.ThrowIfTrue(bitArray.Length % 8 != 0);
writer.WriteInt32(bitArray.Length / 8);
// This will hold the byte that we will write out after we process every 8 bits. This is
// LSB, so we push bits into it from the MSB.
byte b = 0;
for (var i = 0; i < bitArray.Length; i++)
{
if (bitArray[i])
{
b = (byte)(0x80 | b >> 1);
}
else
{
b >>= 1;
}
if ((i + 1) % 8 == 0)
{
// End of a byte, write out the byte
writer.WriteByte(b);
}
}
}
示例15: ExtendToSizeRight
/// <summary>
/// aaa -> 000aaa
/// </summary>
/// <param name="to">Reference to array to put the result</param>
/// <param name="bitArray">Array from where to put</param>
/// <param name="p">Size of the new array</param>
private void ExtendToSizeRight(ref BitArray to, BitArray bitArray, int p)
{
if (to == null)
to = new BitArray(p, false);
for (int i = 0; i < bitArray.Length; i++)
to[i] = bitArray[i];
}