本文整理汇总了C#中BitArray类的典型用法代码示例。如果您正苦于以下问题:C# BitArray类的具体用法?C# BitArray怎么用?C# BitArray使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BitArray类属于命名空间,在下文中一共展示了BitArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: And_EmptyArray
public static void And_EmptyArray()
{
BitArray bitArray1 = new BitArray(0);
BitArray bitArray2 = new BitArray(0);
Assert.Equal(0, bitArray1.And(bitArray2).Length);
}
示例2: UpdateScreen
public void UpdateScreen(BitArray bitData)
{
for (int i = 0; i < pixelsObjects.Count; i++)
{
pixelsObjects[i].SetActive(bitData[i]);
}
}
示例3: Start
// Use this for initialization
void Start () {
object[] obj = GameObject.FindSceneObjectsOfType(typeof (GameObject));
foreach (object o in obj)
{
GameObject g = (GameObject) o;
if(g.GetComponent<PhotoEye>()!=null)
{
if(g.GetComponent<PhotoEye>().IO_name_photoeye==IO_name_photoeye_trigger)
{
g.GetComponent<PhotoEye>().ConnectATR(gameObject);
}
}
}
encoding = new System.Text.ASCIIEncoding();
max_emu_to_plc_io = 1600; // 200 bytes
emu_to_plc_bits = new BitArray(max_emu_to_plc_io);
Logger.WriteLine("[INFO]","STARTUP AtrsCom on port " + ATR_PORT + " linked to photoeye " + IO_name_photoeye_trigger,"",true);
Debug.Log("STARTUP AtrsCom on port " + ATR_PORT + " linked to photoeye " + IO_name_photoeye_trigger+".\r\n");
ready = true;
listenerThread = new Thread(new ThreadStart(DoListen));
listenerThread.Start();
}
示例4: Read
public static string Read()
{
String xd;
using(StreamReader reader = new StreamReader("Output.txt"))
{
xd = reader.ReadToEnd();
}
string[] c = xd.Split(' ');
List<byte> outputs = new List<byte>();
foreach(string x in c)
{
char[] d = x.ToCharArray();
BitArray Out = new BitArray(8);
if (d.Length != 8)
{
continue;
}
for(int i = 0; i < 8; i++)
{
Out[i] = d[i] == 'x';
}
outputs.Add(ConvertToByte(Out));
}
return Encoding.ASCII.GetString(outputs.ToArray());
}
示例5: Main
static void Main()
{
BitArray bits = new BitArray(8);
bits[0] = 1;
bits[7] = 1;
System.Console.WriteLine(bits);
}
示例6: Decode
public static string Decode (Texture2D image){
//Get the pixels for the image...
Color[] imagePixels = image.GetPixels();
//Go Through the First 32 Pixels and create a 4 byte array.
//This array should give us the message's length.
BitArray newBits = new BitArray(32);
for (int i=0;i<32;i++){
if(imagePixels[i].a == 1){
newBits[i] = true;
}
else {
newBits[i] = false;
}
}
int total = System.BitConverter.ToInt32(ToByteArray(newBits), 0);
BitArray messageBits = new BitArray(total);
for (int j=32;j<total + 32;j++){
if(imagePixels[j].a == 1){
messageBits[j-32] = true;
}
else {
messageBits[j-32] = false;
}
}
return System.Text.Encoding.ASCII.GetString(ToByteArray(messageBits));
}
示例7: renderCurrentState
private void renderCurrentState()
{
int i;
BitArray stacks = new BitArray( brain.getKnownObjects().Count );
foreach ( iThinkFact fact in brain.curState.getFactList() )
{
if ( fact.getName().Equals( "onTable" ) )
{
i = findNextFreeStack( stacks );
fact.getObj( 0 ).transform.position = new Vector3( (float)( 1.5 - i * 1.5 ), 0, 0 );
stacks.Set( i - 1, true );
}
}
foreach ( iThinkFact fact in brain.curState.getFactList() )
{
if ( fact.getName().Equals( "on" ) )
{
fact.getObj( 0 ).transform.position = fact.getObj( 1 ).transform.position;
fact.getObj( 0 ).transform.Translate( 0, (float)1.5, 0 );
}
else if ( fact.getName().Equals( "holding" ) )
{
fact.getObj( 0 ).transform.position = new Vector3( -15, 5, 0 );
}
}
}
示例8: Main
static void Main()
{
BitArray bits = new BitArray();
//Random set of bits
for (int i = 0; i < 64; i++)
{
Random random = new Random();
StringBuilder getTime = new StringBuilder();
int randomNumber = (int)DateTime.Now.Ticks;
//Трябва ми време за да се получи добър random
for (int j = 0; j < 100000; j++)
{
Math.Sqrt(j + 1);
}
//Край на губенето на време
if (randomNumber % 2 == 0)
{
bits[i] = 1;
}
}
Console.WriteLine(bits);
//Print all Bits
foreach (var item in bits)
{
Console.Write(item);
}
Console.WriteLine();
}
示例9: Not
public static void Not(int length)
{
BitArray bitArray = new BitArray(length, false);
if (length > 0)
{
bitArray[0] = true;
bitArray[1] = true;
bitArray[length - 2] = true;
bitArray[length - 1] = true;
}
BitArray bitArrayNot = bitArray.Not();
Assert.Equal(bitArray.Length, bitArrayNot.Length);
Assert.Same(bitArray, bitArrayNot);
for (int i = 0; i < bitArray.Length; i++)
{
if (i <= 1 || i >= length - 2)
{
Assert.False(bitArrayNot[i]);
}
else
{
Assert.True(bitArrayNot[i]);
}
}
}
示例10: Main
static void Main()
{
BitArray bits = new BitArray(100000);
bits[99999] = 1;
Console.WriteLine(bits.ToString());
}
示例11: Main
static void Main()
{
BitArray num = new BitArray(8);
num[0] = 1;
num[7] = 1;
Console.WriteLine(num);
}
示例12: Main
static void Main()
{
int n = 10000000;
int m = (int)Math.Sqrt(n);
BitArray sieve = new BitArray(n);
int i = 2;
while (i <= m)
{
for (int j = 2 * i; j < n; j += i)
{
sieve[j] = true;
}
do
{
i++;
}
while (sieve[i] == true);
}
//print just the prime numbers up to 100
for (int j = 2; j < 100; j++)
{
if (sieve[j] == false)
{
Console.WriteLine(j);
}
}
}
示例13: GetBitsStuffed
public BitArray GetBitsStuffed()
{
int nstuff = 0;
bool last = false;
BitArray ba = new BitArray();
foreach (bool bit in GetBitsUnstuffed().Bits())
{
if (bit == last)
nstuff++;
else
{
nstuff = 1;
last = bit;
}
if (nstuff > 5)
{
ba.AddBit(!last);
nstuff = 1;
}
ba.AddBit(bit);
}
return ba;
}
示例14: loadSaveData
public void loadSaveData(int id)
{
currentFlag.SetAll(false);
//load file
string filepath = string.Format("{0}/sav{1}", Application.persistentDataPath, id);
Debug.Log(filepath);
if (!File.Exists(filepath))
{
//show error
return;
}
FileStream fs = File.Open(filepath, FileMode.Open);
BinaryReader reader = new BinaryReader(fs);
currentID = reader.ReadInt32();
byte[] buf = reader.ReadBytes(10);
currentFlag = new BitArray(buf);
for (int i = (int)GameValueType.None; i < (int)GameValueType.Max; i++ )
{
values[(GameValueType)i] = reader.ReadInt32();
}
fs.Flush();
fs.Close();
startGame();
}
示例15: TestSequentialInv
private static void TestSequentialInv(int count)
{
BitArray array = new BitArray(false, count);
for (int x = 0; x < count; x++)
{
if (array.GetBit(x))
throw new Exception("each bit should be cleared");
}
array = new BitArray(true, count);
for (int x = 0; x < count; x++)
{
if (!array.GetBit(x))
throw new Exception("each bit should be set");
}
for (int x = 0; x < count; x++)
{
array.ClearBit(x);
if (array.GetBit(x))
throw new Exception("each bit should be cleared");
array.SetBit(x);
if (!array.GetBit(x))
throw new Exception("each bit should be cleared");
array.ClearBit(x);
if (array.FindSetBit() != (x == count - 1 ? -1 : x + 1))
throw new Exception();
}
}