當前位置: 首頁>>代碼示例>>C#>>正文


C# BitArray類代碼示例

本文整理匯總了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);
 }
開發者ID:SGuyGe,項目名稱:corefx,代碼行數:7,代碼來源:BitArray_OperatorsTests.cs

示例2: UpdateScreen

 public void UpdateScreen(BitArray bitData)
 {
     for (int i = 0; i < pixelsObjects.Count; i++)
     {
         pixelsObjects[i].SetActive(bitData[i]);
     }
 }
開發者ID:jarkkopa,項目名稱:Chip8Unity,代碼行數:7,代碼來源:DisplayBlocks.cs

示例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();
		
		
	}
開發者ID:wiechars,項目名稱:Emulation,代碼行數:34,代碼來源:AtrsCom.cs

示例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());
 }
開發者ID:thedanieldude1,項目名稱:DanielCode,代碼行數:25,代碼來源:Program.cs

示例5: Main

 static void Main()
 {
     BitArray bits = new BitArray(8);
     bits[0] = 1;
     bits[7] = 1;
     System.Console.WriteLine(bits);
 }
開發者ID:Aleksandyr,項目名稱:Software-University,代碼行數:7,代碼來源:Program.cs

示例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));
		
	}
開發者ID:rishabhjoshi,項目名稱:Steganography-1,代碼行數:31,代碼來源:Steganography.cs

示例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 );
            }
        }
    }
開發者ID:bernarde-bgi,項目名稱:ithink-unity3d,代碼行數:29,代碼來源:BlocksWorldAgent.cs

示例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();
        }
開發者ID:nnaidenov,項目名稱:TelerikAcademy,代碼行數:34,代碼來源:BitTest.cs

示例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]);
                }
            }
        }
開發者ID:SGuyGe,項目名稱:corefx,代碼行數:26,代碼來源:BitArray_OperatorsTests.cs

示例10: Main

    static void Main()
    {
        BitArray bits = new BitArray(100000);
        bits[99999] = 1;

        Console.WriteLine(bits.ToString());
    }
開發者ID:shnogeorgiev,項目名稱:Software-University-Courses,代碼行數:7,代碼來源:BitArrayDemo.cs

示例11: Main

 static void Main()
 {
     BitArray num = new BitArray(8);
     num[0] = 1;
     num[7] = 1;
     Console.WriteLine(num);
 }
開發者ID:TzvetanIG,項目名稱:OOP,代碼行數:7,代碼來源:TestBitArray.cs

示例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);
            }
        }
    }
開發者ID:andon-andonov,項目名稱:TelerikAcademy,代碼行數:29,代碼來源:SieveOfEratosthenes.cs

示例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;
    }
開發者ID:BuFran,項目名稱:canshark,代碼行數:26,代碼來源:CanMessage.cs

示例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();
    }
開發者ID:ancongsheng,項目名稱:vu_paradox,代碼行數:31,代碼來源:MainGame.cs

示例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();
            }
        }
開發者ID:GridProtectionAlliance,項目名稱:openHistorian,代碼行數:29,代碼來源:BitArrayTest.cs


注:本文中的BitArray類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。