User Rating 0.0
Total Usage 0 times
Bit Width
Dec: 0
Dec: 0
Presets
Is this tool helpful?

Your feedback helps us improve.

About

The bitwise AND operation compares each bit of two operands and produces 1 only when both corresponding bits equal 1. This is the foundational gate in digital logic design. Misapplying AND masks in firmware or network subnet calculations leads to silent data corruption or routing failures that surface hours after deployment. This calculator accepts binary strings up to 32 bits, applies the AND operation per the IEEE standard binary representation, and returns results in binary, decimal, hexadecimal, and octal. It assumes unsigned integer representation. Inputs exceeding the selected bit width are truncated from the most significant bit side.

Bitwise AND is used in subnet masking (e.g., applying mask M to IP address A via A & M), permission flag extraction, register-level hardware control, and graphics pixel channel isolation. A common error is confusing logical AND () with bitwise AND (&). Logical AND evaluates truth of entire expressions. Bitwise AND operates on each bit independently. This tool visualizes every bit position to eliminate that confusion.

bitwise AND binary calculator AND gate binary operations bit manipulation boolean algebra

Formulas

The bitwise AND operation on two n-bit unsigned integers A and B is defined as:

R = A & B

For each bit position i from 0 to n 1:

Ri = Ai Bi

Where Ri = 1 if and only if both Ai = 1 and Bi = 1. The decimal value of a binary number is computed as:

D = n1i=0 bi 2i

Where bi is the bit value at position i (counting from the least significant bit). Hexadecimal conversion groups bits into 4-bit nibbles from the right. Octal conversion groups bits into 3-bit groups from the right.

Key algebraic properties of bitwise AND:

A & A = A(idempotent)
A & 0 = 0(annihilation)
A & ¬A = 0(complement)
A & B = B & A(commutative)

Reference Data

Bit ABit BA AND BGate SymbolBoolean Expression
000&A B = 0
010&A B = 0
100&A B = 0
111&A B = 1
Common AND MaskBinary (8-bit)DecimalHexPurpose
Low nibble00001111150x0FExtract lower 4 bits
High nibble111100002400xF0Extract upper 4 bits
Even test0000000110x01Check if number is odd
Byte mask111111112550xFFIsolate lowest byte
Alignment (4)111111002520xFCRound down to multiple of 4
Clear bit 3111101112470xF7Force bit 3 to 0
Subnet /24111111112550xFFEach octet of 255.255.255.0
Subnet /16111111112550xFFEach octet of 255.255.0.0
RGB Red channel11111111 00000000 00000000167116800xFF0000Extract red from 24-bit color
Permission read0000010040x04Unix read permission flag
Permission write0000001020x02Unix write permission flag
Permission exec0000000110x01Unix execute permission flag
Power-of-2 testn & (n 1) = 0True if n is power of 2
Sign bit (32-bit)10000000 00000000 00000000 0000000021474836480x80000000Extract sign of signed int

Frequently Asked Questions

Logical AND (typically &&) evaluates two boolean expressions and returns TRUE or FALSE. It uses short-circuit evaluation: if the first operand is false, the second is never evaluated. Bitwise AND (&) operates on every bit of two integer operands independently. For example, 6 (110) & 3 (011) = 2 (010). Logical AND on the same values: both are truthy, so the result is TRUE. Confusing the two in C or Java causes subtle bugs that compile without warnings.
This calculator pads the shorter operand with leading zeros to match the selected bit width. This is identical to how hardware registers work: an 8-bit register stores 101 as 00000101. The AND operation then proceeds bit-by-bit across equal-length strings. If your input exceeds the selected bit width, it is truncated from the most significant bit side, which may change the decimal value.
An IP address like 192.168.1.45 ANDed with subnet mask 255.255.255.0 produces the network address 192.168.1.0. Each octet is ANDed independently. The mask's 1 bits preserve the network portion. The mask's 0 bits zero out the host portion. This is how routers determine if two hosts are on the same network segment. An incorrect mask causes packets to be routed instead of switched locally, increasing latency.
Yes. The expression n & (n 1) equals 0 if and only if n is a power of 2 (and n > 0). A power of 2 in binary has exactly one 1 bit. Subtracting 1 flips that bit and sets all lower bits to 1. ANDing them yields zero. Example: 8 (1000) & 7 (0111) = 0.
In a 24-bit RGB color value, the red channel occupies bits 16 - 23. To isolate it: color & 0xFF0000, then right-shift by 16. Similarly, AND with 0x00FF00 isolates green, and 0x0000FF isolates blue. Alpha blending, transparency masks, and sprite collision detection in game engines all rely on these bitwise AND masks applied per-pixel.
This calculator supports up to 32-bit unsigned integers (maximum value 4294967295). JavaScript internally uses 64-bit floats, but bitwise operators coerce operands to 32-bit signed integers. For unsigned 32-bit AND, the calculator uses unsigned right shift (>>> 0) to force unsigned interpretation. Inputs exceeding 32 bits are not supported because JavaScript's native & operator truncates to 32 bits.