Bitwise Calculator: AND, OR, XOR, Shift Operations and Flag Manipulation Explained
Bitwise operations are the knife-edge of programming — they operate on individual bits within a byte or word, giving you direct control over the raw binary representation of data. Where arithmetic operates on numbers as abstract values, bitwise operations manipulate the 1s and 0s themselves. This is how file permissions are encoded in a single integer on Unix, how graphics programmers extract RGB channels from a pixel value, how network protocols pack multiple flags into a single header byte, and how fast hash functions and checksums are built. Our free bitwise calculator takes two operands (or one for NOT and shifts), performs the selected operation at the bit level, and displays the result in binary, hexadecimal, and decimal simultaneously — with each bit position labeled so you can verify exactly what happened where.
Bitwise Calculator
Free · No registration
Step-by-Step Guide
Enter Your Operands
Type two numbers in decimal, hexadecimal (prefix with 0x), or binary (prefix with 0b). The calculator accepts 32-bit and 64-bit mode — in 32-bit mode, operands are treated as unsigned 32-bit integers (0 to 4,294,967,295). Each operand is displayed in binary format with bit positions numbered from 31 (most significant) down to 0 (least significant), so you can visualise exactly which bits are set before applying any operation.
Select the Bitwise Operation
Choose from seven operations: AND (&) sets a result bit to 1 only if both corresponding operand bits are 1; OR (|) sets it to 1 if either operand bit is 1; XOR (^) sets it to 1 if exactly one operand bit is 1; NOT (~) inverts every bit of a single operand; left shift (<<) moves all bits left by N positions (filling with zeros on the right); logical right shift (>>>) moves bits right with zero-fill; arithmetic right shift (>>) moves bits right with sign-bit fill. The calculator animates the operation — showing which input bits contribute to each output bit.
Read the Multi-Format Result and Bit Map
The result displays in binary (32 bits with spacing every 4 bits for readability), hexadecimal (8 hex digits for 32-bit), and decimal. A visual bit map highlights which positions are 1 in the result, and hovering over any bit shows which input bits produced it. The copy buttons let you grab the result in any format instantly — binary for documentation, hex for code, decimal for calculations.
Tips & Best Practices
Bit masking is the most common bitwise pattern: use AND with a mask to extract specific bits. To get the lowest 8 bits of a 32-bit value: value & 0xFF (255). To test if bit 3 is set: (value & (1 << 3)) !== 0. To clear bit 5: value & ~(1 << 5). To set bit 7: value | (1 << 7). To toggle bit 2: value ^ (1 << 2). These four patterns — test, clear, set, toggle — cover 90% of bit manipulation in practice.
Color channel extraction is a classic bitwise use case. An RGB pixel packed into a 32-bit integer (0xRRGGBB) can be unpacked with: red = (pixel >> 16) & 0xFF, green = (pixel >> 8) & 0xFF, blue = pixel & 0xFF. In one line, you've extracted three colour channels using right shift and AND masks. ARGB (alpha channel) uses the top 8 bits: alpha = (pixel >> 24) & 0xFF.
Left shift by 1 position multiplies by 2; right shift by 1 position divides by 2 (integer division, rounding toward zero for arithmetic shift, toward negative infinity for logical). Left shift by N is equivalent to multiplying by 2ᴺ. Right shift by N is equivalent to dividing by 2ᴺ. CPUs execute shifts in a single clock cycle, making them dramatically faster than general multiplication/division for powers of 2.
XOR swap is a classic trick to swap two variables without a temporary variable: a ^= b; b ^= a; a ^= b. After this sequence, a and b have exchanged values. It works because XOR is commutative, associative, and x ^ x = 0, x ^ 0 = x. In modern code, this is mainly a curiosity — compilers optimise standard swaps equally well — but it's a great demonstration of XOR's algebraic properties.
Permission flags pack multiple on/off settings into a single integer. Unix file permissions use 12 bits: the bottom 9 are rwx for owner/group/others (each r=4, w=2, x=1). Higher bits encode setuid (4000), setgid (2000), and sticky (1000). Each permission is a single flag that can be tested or modified independently — this is the pattern behind virtually every flags parameter in every C API.
CRC (Cyclic Redundancy Check) and checksum calculations use XOR and shift operations heavily. A basic CRC-8 implementation XORs each byte of data into a running register, then shifts and conditionally XORs with a polynomial. This produces an 8-bit "fingerprint" that detects accidental changes to data. Our calculator lets you step through such algorithms bit by bit to see how they work.
The right shift operator comes in two flavours: logical (>>> in JavaScript/Java), which fills the vacated leftmost bits with zeros; and arithmetic (>> in most languages), which fills them with copies of the sign bit (preserving the sign for signed integers). Right-shifting -8 (11111000 in 8-bit signed) by 1 with arithmetic shift produces -4 (11111100); with logical shift it produces 124 (01111100), a completely different value.
Frequently Asked Questions
Bitwise operations are the smallest and fastest operations a computer can perform — literally one CPU cycle, one logic gate layer deep. Our calculator makes these operations visible, showing exactly which bits change and why. Whether you're packing flags, extracting colour channels, or debugging a cryptography implementation, see your bits in full detail.
Try this tool for free →open_in_new