Bitwise Calculator

Perform bitwise AND, OR, XOR, NOT, shifts, NAND, and NOR. Input in decimal, binary (0b), or hex (0x). See results in all formats.

0
Decimal
Operation
&

Inputs

Enter values in decimal, binary (0b prefix), or hex (0x prefix).

= 170 (dec) = 10101010 (bin)
= 85 (dec) = 01010101 (bin)

Relevant tools

Browse all →

Quick internal links for related tools.

How to use the bitwise calculator

Enter two values in the input fields using decimal (170), binary (0b10101010), or hexadecimal (0xFF) notation. Select a bitwise operation from the operation buttons. The result updates instantly in decimal, binary, and hexadecimal formats. For unary operations like NOT, only Value A is used.

The binary visualization panel shows each bit of both operands and the result as colored blocks. Orange bits belong to Value A, blue bits to Value B, and green bits to the result. This visual representation makes it easy to see exactly how each bit is affected by the operation—especially useful when learning or debugging bitmask logic.

Choose the display bit width (8, 16, or 32) to match your use case. For byte-level operations, 8-bit is appropriate. For networking and protocol work, 16-bit or 32-bit is common. The calculator handles negative numbers using two's complement representation, which is the standard for signed integers in virtually all modern processors.

Common use cases for bitwise operations

Bitmasks and flags are the most common application. Instead of using separate boolean variables, you pack multiple flags into a single integer. Each bit represents a different option. Use OR to set flags (flags | FLAG), AND with NOT to clear flags (flags & ~FLAG), XOR to toggle flags (flags ^ FLAG), and AND to check flags (flags & FLAG).

In networking, bitwise AND is used with subnet masks to determine network addresses. An IP address (e.g., 192.168.1.100) ANDed with a subnet mask (e.g., 255.255.255.0) gives the network address (192.168.1.0). CIDR notation like /24 means the first 24 bits are the network portion, equivalent to a mask of 0xFFFFFF00.

Bit shifting is used for fast multiplication and division by powers of 2. Left shift by 1 doubles a value, left shift by 3 multiplies by 8. Right shift by 1 halves a value (integer division). This is faster than multiplication in low-level code and is commonly used in embedded systems, game engines, and performance-critical algorithms. Compilers often optimize multiplication by powers of 2 into shifts automatically.

Bitwise operations in programming languages

Most programming languages use the same symbols for bitwise operations: & (AND), | (OR), ^ (XOR), ~ (NOT), << (left shift), >> (right shift). C, C++, Java, JavaScript, Python, Rust, Go, and Swift all follow this convention. JavaScript is unique in that it converts operands to 32-bit signed integers before performing bitwise operations, then converts back—this can produce unexpected results with large numbers.

Python supports arbitrary-precision integers, so bitwise operations work on numbers of any size without overflow. In C and C++, shifting by more than the bit width of the type is undefined behavior. Java specifies that shift amounts are masked to the type width (e.g., int shift is masked to 5 bits, so shifting by 33 is the same as shifting by 1). Understanding these language-specific behaviors is important for writing correct cross-platform code.

Frequently Asked Questions

What are bitwise operations?

Bitwise operations work on individual bits of integer values. They compare or manipulate numbers at the binary level, one bit at a time. AND (&) returns 1 only when both bits are 1. OR (|) returns 1 when either bit is 1. XOR (^) returns 1 when bits are different. NOT (~) inverts every bit. These operations are fundamental in systems programming, networking, cryptography, and hardware design.

When would I use bitwise AND?

Bitwise AND is commonly used for masking—extracting specific bits from a value. For example, value & 0xFF extracts the lowest 8 bits. In networking, subnet masks use AND to determine network addresses: IP & mask = network address. AND is also used to check if a specific bit is set: if (flags & FLAG_BIT) checks whether a particular flag is enabled in a bitmask.

What is the difference between XOR and OR?

OR returns 1 when either or both bits are 1, while XOR (exclusive OR) returns 1 only when the bits are different. XOR has a unique property: A ^ B ^ B = A, making it useful for encryption, checksums, and toggling bits. XOR swap (a ^= b; b ^= a; a ^= b;) exchanges two values without a temporary variable. In cryptography, XOR is the basis of many stream ciphers.

How do bit shifts work?

Left shift (<<) moves all bits to the left by a specified number of positions, filling vacated bits with zeros. Each left shift by 1 effectively multiplies by 2. Right shift (>>) moves bits to the right, with the fill bit depending on the implementation (arithmetic shift preserves the sign bit, logical shift fills with zeros). Right shift by 1 effectively divides by 2 (integer division).

What are NAND and NOR?

NAND (NOT AND) is the inverse of AND—it returns 0 only when both bits are 1, otherwise 1. NOR (NOT OR) is the inverse of OR—it returns 1 only when both bits are 0. NAND and NOR are universal gates in hardware design, meaning any logical operation can be constructed using only NAND gates or only NOR gates. They are fundamental building blocks of digital circuits.

Can I input binary or hexadecimal values?

Yes. Prefix binary values with 0b (e.g., 0b10101010) and hexadecimal values with 0x (e.g., 0xFF). Octal values use the 0o prefix (e.g., 0o377). Values without a prefix are interpreted as decimal. The calculator automatically parses the input and displays the result in binary, hexadecimal, and decimal formats.

Privacy and methodology

This tool runs entirely in your browser using JavaScript bitwise operators. Values are parsed as integers with support for decimal, binary (0b), hexadecimal (0x), and octal (0o) prefixes. All calculations happen locally—no data is sent to any server. JavaScript bitwise operations use 32-bit signed integers internally, which is reflected in the results for NOT and shift operations on large values.

Tool Vault — Bitwise Calculator 2026. Fast, private, and mobile-friendly.