Home  |  Delphi .net Home  |  System.Collections.BitArray  |  And Method
  
And  
Method  
Perform a logical And of one BitArray against another
BitArray Class
System.Collections NameSpace
CF1.  Procedure And ( Source : BitArray ) ;
CF : Methods with this mark are Compact Framework Compatible
Description
The Source BitArray elements are logically Anded with the elements of the current BitArray. The resultant values are stored in a new BitArray that is returned.
Notes
IMPORTANT : you must prefix the method name And with an & to avoid a compiler error, where the method name is confused with the native Delphi operator.
Microsoft MSDN Links
System.Collections
System.Collections.BitArray
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.Collections;

var
  Source1, Source2, Target : System.Collections.BitArray;
  i                        : Integer;

begin
  // Create our bit arrays
  Source1 := System.Collections.BitArray.Create(4);
  Source2 := System.Collections.BitArray.Create(4);
  Target  := System.Collections.BitArray.Create(4);

  // Set the values in both arrays
  Source1[0] := false;  // 0
  Source1[1] := false;  // 0
  Source1[2] := true;   // 1
  Source1[3] := true;   // 1

  Source2[0] := false;  // 0
  Source2[1] := true;   // 1
  Source2[2] := false;  // 0
  Source2[3] := true;   // 1

  for i := 0 to Source1.Count-1 do
    if Source1[i]
    then Console.WriteLine('Source1 [{0}] = 1', i.ToString)
    else Console.WriteLine('Source1 [{0}] = 0', i.ToString);

  Console.WriteLine;
  Console.WriteLine('And');
  Console.WriteLine;

  for i := 0 to Source2.Count-1 do
    if Source2[i]
    then Console.WriteLine('Source2 [{0}] = 1', i.ToString)
    else Console.WriteLine('Source2 [{0}] = 0', i.ToString);

  // Perform a logical AND of Source onto Target :
  Target := Source1.&And(Source2);   // Note the &

  Console.WriteLine;
  Console.WriteLine(' =');
  Console.WriteLine;

  for i := 0 to Target.Count-1 do
    if Target[i]
    then Console.WriteLine('Target [{0}] = 1', i.ToString)
    else Console.WriteLine('Target [{0}] = 0', i.ToString);

  Console.ReadLine;
end.
   Source1 [0] = 0
   Source1 [1] = 0
   Source1 [2] = 1
   Source1 [3] = 1
  
   And
  
   Source2 [0] = 0
   Source2 [1] = 1
   Source2 [2] = 0
   Source2 [3] = 1
  
   =
  
   Target [0] = 0
   Target [1] = 0
   Target [2] = 0
   Target [3] = 1
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author