bitAnd

x & y

bitAnd(x, y)

Try it yourself:


bitAnd(): combine matching bits

bitAnd(a, b) performs a bitwise AND. A result bit is 1 only when the corresponding bit is 1 in both inputs. For example, bitAnd(12, 10) compares 1100 and 1010, producing 1000, or 8.

Masks and permissions

AND is the standard way to test a bit mask. If a flag is present in a value, bitAnd(value, flag) returns a non-zero result. This is compact and fast for sets of Boolean options such as feature switches or file permissions.

Inspect the calculation

Use bin() to see both operands in binary. To set flags, use bitOr(); to toggle differences, use bitXor(). bitNot() can clear selected positions when combined carefully.

Input rules

Bitwise operations are intended for integers. Decide explicitly how to handle decimal inputs, and be cautious with negative numbers because signed binary representations and width conventions affect their interpretation. For logical truth values rather than integer bits, use and.

Try Bit And in Calcul.io

Start with one of the editable examples above, then replace its arguments with your own values. Keeping the function on a separate calculator line makes the input and result easy to compare. For a longer workflow, assign the result to a variable or reference that line in the next expression.

Check the shown signature before adding optional arguments, and use the related-function links to compare operations with similar purposes.

All functions