({{, (RefLink[BitAnd, paclet:ref/BitAnd])[(Subscript[n, 1]),(Subscript[n, 2]),…]
gives the bitwise AND of the integers (Subscript[n, i]). }})

OpenersNotesSection(Spacer1)Details

Integer mathematical function, suitable for both symbolic and numerical manipulation.

(RefLink[BitAnd, paclet:ref/BitAnd])[(Subscript[n, 1]),(Subscript[n, 2]),…] yields the integer whose binary bit representation has ones at positions where the binary bit representations of all of the (Subscript[n, i]) have ones.

For negative integers (RefLink[BitAnd, paclet:ref/BitAnd]) assumes a two's complement representation.

(RefLink[BitAnd, paclet:ref/BitAnd]) automatically threads over lists.

OpenersPrimaryExamplesSection(Spacer1)Examples  (13)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

BitAnd[61,15]

IntegerDigits[{61,15,13},2,6]//Column

OpenersExampleSection1(Spacer1)Scope  (3)

Use numbers of any size:

BitAnd[3^100,5^100]

(RefLink[BitAnd, paclet:ref/BitAnd]) takes any number of arguments:

BitAnd[3333,5555,7777,9999]

Use negative numbers:

BitAnd[-2,-3]

OpenersExampleSection2(Spacer1)Generalizations & Extensions  (1)

Basic symbolic simplifications are done automatically:

BitAnd[x,y,y,x]

BitAnd[3,5,x]

BitAnd[1,2,x]

OpenersExampleSection3(Spacer1)Applications  (5)

Extract the second-lowest-order bits in numbers:

Table[BitAnd[i,2],{i,10}]

"Mask" to test whether bits 3 or 4 are 1:

Table[Sign[BitAnd[i,2^2+2^3]],{i,16}]

Make a nested pattern:

ArrayPlot[Table[Boole[BitAnd[i,j]==0],{i,0,63},{j,0,63}]]

ListLinePlot[Table[BitAnd[i,i-1],{i,100}]]

Test for powers of 2:

Table[Boole[BitAnd[i,i-1]==0],{i,20}]

ListLinePlot[Table[BitAnd[i,2i],{i,64}]]

ListLinePlot[Table[BitAnd[i,2i,3i],{i,64}]]

OpenersExampleSection4(Spacer1)Properties & Relations  (2)

Truth table for (RefLink[And, paclet:ref/And]):

Grid[Outer[BitAnd,{1,0},{1,0}]]

(RefLink[BitAnd, paclet:ref/BitAnd]) is (RefLink[Orderless, paclet:ref/Orderless]):

BitAnd[y,x]

OpenersExampleSection5(Spacer1)Neat Examples  (1)

ArrayPlot[Array[BitAnd,{63,63}]]

Graphics3D[Table[Cuboid[{i,j,BitAnd[i,j]}],{i,31},{j,31}]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[BitOr, paclet:ref/BitOr])  ▪  (RefLink[BitXor, paclet:ref/BitXor])  ▪  (RefLink[BitNot, paclet:ref/BitNot])  ▪  (RefLink[BitGet, paclet:ref/BitGet])  ▪  (RefLink[And, paclet:ref/And])  ▪  (RefLink[IntegerDigits, paclet:ref/IntegerDigits])  ▪  (RefLink[DigitCount, paclet:ref/DigitCount])  ▪  (RefLink[CellularAutomaton, paclet:ref/CellularAutomaton])  ▪  (RefLink[Pick, paclet:ref/Pick])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Integer and Number Theoretic Functions, paclet:tutorial/IntegerAndNumberTheoreticalFunctions])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Bitwise Operations, paclet:guide/BitwiseOperations])}, {▪(RefLinkPlain[Boolean Computation, paclet:guide/BooleanComputation])}, {▪(RefLinkPlain[Representation of Numbers, paclet:guide/RepresentationOfNumbers])}, {▪(RefLinkPlain[Number Digits, paclet:guide/NumberDigits])}, {▪(RefLinkPlain[Integer Functions, paclet:guide/IntegerFunctions])}, {▪(RefLinkPlain[Discrete Mathematics, paclet:guide/DiscreteMathematics])}, {▪(RefLinkPlain[Cryptographic Number Theory, paclet:guide/CryptographicNumberTheory])}, {▪(RefLinkPlain[Mathematical Functions, paclet:guide/MathematicalFunctions])}})}})

({{(Spacer1), ({{(Spacer1)Related Links}, {(WebLink[DocumentationFooterIconsRelatedLinks-NKS.png(Spacer1)NKS|Online, http://www.wolframscience.com/nksonline/index/search.cgi?SearchIndex=BitAnd]) ((WebLink[A New Kind of Science, http://www.wolframscience.com/nksonline/]))}})}})