BitAnd[n1,n2,…]
gives the bitwise AND of the integers ni.
BitAnd
BitAnd[n1,n2,…]
gives the bitwise AND of the integers ni.
Details
- Integer mathematical function, suitable for both symbolic and numerical manipulation.
- BitAnd[n1,n2,…] yields the integer whose binary bit representation has ones at positions where the binary bit representations of all of the ni have ones. »
- For negative integers BitAnd assumes a two's complement representation.
- BitAnd automatically threads over lists. »
Examples
open all close allBasic Examples (1)
Scope (4)
BitAnd[3 ^ 100, 5 ^ 100]BitAnd takes any number of arguments:
BitAnd[3333, 5555, 7777, 9999]BitAnd[-2, -3]Basic symbolic simplifications are done automatically:
BitAnd[x, y, y, x]BitAnd[3, 5, x]BitAnd[1, 2, x]Applications (7)
Extract the second-lowest-order bits in numbers:
Table[BitAnd[i, 2], {i, 10}]Truth table for And:
Grid[Outer[BitAnd, {1, 0}, {1, 0}]]"Mask" to test whether bits 3 or 4 are 1:
Table[Sign[BitAnd[i, 2 ^ 2 + 2 ^ 3]], {i, 16}]TableForm[Table[{i, BitAnd[i, i - 1] == 0}, {i, 20}]]ArrayPlot[Table[Boole[BitAnd[i, j] == 0], {i, 0, 63}, {j, 0, 63}]]This structure corresponds to the Sierpiński gasket:
SierpinskiMesh[5]Plot the BitAnd of
with
:
ListLinePlot[Table[BitAnd[i, i - 1], {i, 100}]]Plot the BitAnd of
with
:
ListLinePlot[Table[BitAnd[i, 2i], {i, 64}]]Plot the BitAnd of
with
and
:
ListLinePlot[Table[BitAnd[i, 2i, 3i], {i, 64}]]Properties & Relations (4)
-1 corresponds to having all bits on:
BitAnd[-1, 2, x]The BitAnd of any number of copies of a number with itself is that number:
BitAnd[x, x]BitAnd[x, x, x]BitAnd automatically threads over lists:
BitAnd[5, Range[10]]BitAnd[y, x]Neat Examples (1)
Plotting BitAnd[x,y] in the plane shows a nested pattern of squares:
ArrayPlot[Array[BitAnd, {63, 63}]]Plotting in three dimensions reveals a fractal structure:
Graphics3D[Table[Cuboid[{i, j, BitAnd[i, j]}], {i, 31}, {j, 31}]]This structure corresponds to the Sierpiński sponge:
SierpinskiMesh[5, 3]See Also
BitOr BitXor BitNot BitGet And IntegerDigits DigitCount CellularAutomaton Pick
Function Repository: BitBooleanFunction
Tech Notes
Related Links
History
Introduced in 1999 (4.0)
Text
Wolfram Research (1999), BitAnd, Wolfram Language function, https://reference.wolfram.com/language/ref/BitAnd.html.
CMS
Wolfram Language. 1999. "BitAnd." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/BitAnd.html.
APA
Wolfram Language. (1999). BitAnd. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/BitAnd.html
BibTeX
@misc{reference.wolfram_2026_bitand, author="Wolfram Research", title="{BitAnd}", year="1999", howpublished="\url{https://reference.wolfram.com/language/ref/BitAnd.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_bitand, organization={Wolfram Research}, title={BitAnd}, year={1999}, url={https://reference.wolfram.com/language/ref/BitAnd.html}, note=[Accessed: 12-June-2026]}