Calculate A & B online and see exactly which bit positions stay active when both input bits are 1.
Number A
Dec46Bin00101110Hex0x2E
Invalid input.
Value exceeds selected bit width.
Number B
Dec74Bin01001010Hex0x4A
Invalid input.
Value exceeds selected bit width.
AND Result
AND (&)
Dec0
Hex0x00
Bin00000000
Bit-by-Bit Visualization
1 Active bit0 Diff bit0 Included zero0 Leading zero
AND Truth Table
Click a row to load values into A and B, or inspect how each gate behaves.
Input A
Input B
AND
0
0
0
0
1
0
1
0
0
1
1
1
Click a truth table row to test those values.
Copied.
How the Bitwise AND Calculator Works
A bitwise AND calculator compares two integers bit by bit. The result keeps a 1 only where both inputs contain 1, which makes AND useful for masks, permissions, and field extraction.
&
AND Rule
The output bit is 1 only when the matching bit in A and B is also 1.
0
Clearing Bits
Any input column containing a 0 returns 0, so AND is commonly used to clear unwanted bits.
#
Mask Checks
Use AND to isolate a flag, permission bit, protocol field, or packed integer segment.
01
Aligned Binary
The calculator aligns both binary values so every column can be compared directly.
Bitwise AND Calculation Steps
Follow these steps to calculate a bitwise AND result manually.
Align the Inputs
Convert both values to binary.
Pad the shorter value with leading zeros.
Place matching bit positions in the same column.
Compare Each Column
Write 1 if both input bits are 1.
Write 0 if either input bit is 0.
Keep the selected bit width when displaying the answer.
Use the Mask Result
Read the result as binary.
Convert it to decimal or hexadecimal.
Apply it to isolate or test specific flags.
Bitwise AND Examples
AND examples show how masks keep only the shared active bits.
Input
Operation
Result
Use
101110 & 1001010
AND
001010
Shared active bits only
11110000 & 00111100
AND
00110000
Nibble mask
0x2E & 0x4A
AND
0x0A
Hex mask result
46 & 74
AND
10
Decimal integer result
Why Use This Bitwise AND Calculator?
Use this AND calculator when you need a quick mask result with visible bit alignment.
&
Mask Preview
See which data bits survive a mask before you hard-code it in C, Python, or JavaScript.
0x
Three Number Bases
Enter A and B in binary, decimal, or hex and read the AND result in all three formats.
8
Register Widths
Switch between auto, 8, 16, 32, and 64 bits to match uint8_t, uint16_t, or 64-bit fields.
01
Column Highlighting
The bit grid marks the positions where both inputs are 1, so you can confirm a mask at a glance.
Practical Uses for Bitwise AND
AND is one of the most common bitwise operations in systems programming.
IP
Subnet Calculation
IP address AND subnet mask gives the network address used by routers.
?
Flag Testing
status & FLAG is non-zero when a status bit is set.
x
Clearing Bits
value & ~FLAG turns off one flag while leaving the others untouched.
%
Fast Modulo
n & (2^k - 1) equals n % 2^k for unsigned integers, a common hot-loop optimisation.
What the Bitwise AND Operator Does
Bitwise AND (&) compares two integers one bit position at a time. Each output bit is 1 only when both input bits in that column are 1. If either bit is 0, the output bit is 0.
A
B
A & B
0
0
0
0
1
0
1
0
0
1
1
1
A useful way to think about AND is as a filter. One operand holds the data, and the other operand is a mask that decides which bits are allowed through. A 1 in the mask keeps the matching data bit, and a 0 in the mask forces that bit to zero.
AND never produces a larger number than either input. For non-negative integers, A & B is always less than or equal to both A and B. That property makes it a quick sanity check when you are debugging mask logic.
Worked Example: 46 & 74 Step by Step
Take the calculator’s default values, 46 and 74.
Convert both values to binary: 46 = 0101110 and 74 = 1001010.
Pad them to the same width (8 bits here): 00101110 and 01001010.
Compare each column from right to left and keep a 1 only where both rows have a 1.
Only bit 1 (value 2) and bit 3 (value 8) are set in both numbers, so the answer is 2 + 8 = 10. In hexadecimal, 0x2E & 0x4A = 0x0A. You can check each nibble on its own: 2 & 4 = 0 and E & A = A.
Bit Masks: Reading, Testing, and Clearing Bits
Most real-world AND code does one of three jobs.
Test whether a flag is set. Put a single 1 in the mask at the flag’s position. If the result is non-zero, the flag is on.
#define FLAG_READY (1u << 3) /* 0b00001000 */if (status & FLAG_READY) { /* bit 3 is set */}
Extract a field. To read the low 4 bits (the low nibble) of a byte, AND with 0x0F. To read a field higher up, shift first and then mask: (value >> 4) & 0x0F returns the high nibble.
Clear bits. Combine AND with NOT. value & ~FLAG_READY keeps every bit except bit 3, which is forced to 0. This is the standard way to turn a flag off without touching its neighbours.
Subnet Masks: AND in Networking
IPv4 routing is a direct application of bitwise AND. A host’s network address is its IP address AND its subnet mask, applied to all 32 bits.
Because the last octet of the mask is all zeros, the host part (77) is cleared and the network part survives. Two devices are on the same subnet when ipA & mask == ipB & mask. Enter each octet in the calculator above with an 8-bit width to check a mask by hand.
Even, Odd, and Power-of-Two Checks
Two small AND tricks show up in interviews and in performance-sensitive code:
Even or odd:n & 1 is 1 for odd numbers and 0 for even numbers, because bit 0 is the only odd-valued bit.
Power of two: a positive integer n is a power of two when (n & (n - 1)) == 0. Subtracting 1 flips the lowest set bit and every bit below it, so a single set bit cancels out completely.
Fast modulo by a power of two: for unsigned values, n % 8 equals n & 7. The mask 2^k - 1 keeps the remainder bits.
These work because AND looks at bits directly instead of performing division.
Bitwise AND in C, Python, and JavaScript
The & symbol is the same in all three languages, but the integer models are different.
# Python: integers have unlimited precisionprint(46 & 74) # 10print(bin(0b101110 & 0b1001010)) # 0b1010print(-1 & 0xFF) # 255 (mask negative numbers to a fixed width)
// JavaScript: operands are converted to signed 32-bit integersconsole.log(46 & 74); // 10console.log(0xFFFFFFFF & 0xFF); // 255console.log(2 ** 32 & 1); // 0 (high bits are discarded)// Use BigInt for 64-bit masks:console.log((2n ** 40n + 5n) & 0xFFn); // 5n
#include <stdint.h>uint8_t low = value & 0x0F; /* low nibble */uint8_t high = (value >> 4) & 0x0F; /* high nibble */
Common Mistakes With Bitwise AND
Mixing up & and &&.&& is logical AND and returns true or false. 6 && 3 is true, but 6 & 3 is 2.
Operator precedence in C-family languages.== binds tighter than &, so x & MASK == 0 is parsed as x & (MASK == 0). Always write (x & MASK) == 0.
Signed values in JavaScript.0x80000000 & 0x80000000 returns -2147483648, not 2147483648, because results are signed 32-bit. Add >>> 0 to read the result as unsigned.
Choosing the wrong width. A mask such as ~0x0F means different things at 8 and 32 bits. Set the same width in the calculator as the type you use in code.
Find answers to common questions about bitwise operations and this online tool.
What does bitwise AND do?
Bitwise AND compares two integers bit by bit and returns 1 in each position where both inputs have a 1. Every other position becomes 0. For example, 46 & 74 = 10 because only bits 1 and 3 are set in both numbers.
What is the difference between & and && ?
& is bitwise AND and returns an integer built from individual bits. && is logical AND and returns true or false. In C or JavaScript, 6 & 3 is 2, while 6 && 3 is simply true (or 3 in JavaScript).
How do I check if a bit is set using AND?
AND the value with a mask that has a single 1 at the bit you care about, for example value & (1 << 3). If the result is non-zero, bit 3 is set.
How is AND used with subnet masks?
A network address is the IP address AND the subnet mask. For 192.168.10.77 with mask 255.255.255.0, the result is 192.168.10.0. Two hosts are on the same subnet when their IP addresses produce the same result.
How can AND tell if a number is even or odd?
Check n & 1. The result is 1 for odd numbers and 0 for even numbers because bit 0 is the only bit with an odd place value.
Why does x & MASK == 0 give the wrong answer in C?
In C, C++, Java, and JavaScript, == has higher precedence than &, so the expression is parsed as x & (MASK == 0). Write (x & MASK) == 0 instead.
Can the result of AND be larger than the inputs?
No. For non-negative integers, A & B is always less than or equal to both A and B, because AND can only keep or clear bits, never set new ones.