Bitwise Calculator 2026 | AND, OR, XOR, NOT & Bit Shifts

Bitwise Calculator

Calculate AND, OR, XOR, NOT and bit shifts with interactive binary diagrams. Free and instant.

Try examples:

Use this Bitwise Calculator to perform AND, OR, XOR, NOT, and bit-shift operations on integers. Enter your values in binary, decimal, or hexadecimal, select a bit width, and examine the results with interactive binary diagrams. You can calculate individual operations or compare AND, OR, and XOR results together.

Working with bitmasks, checking permissions, or debugging binary logic? The calculator shows numerical results alongside their binary and hexadecimal representations, helping you understand which bits change and why. Select a result to inspect the calculation one bit at a time.

Quick Answer: How Does a Bitwise Calculator Work?

A bitwise calculator applies logical operations to the individual binary digits (0s and 1s) of integers. AND returns 1 when both corresponding bits are 1, OR returns 1 when either bit is 1, and XOR returns 1 when the bits differ. NOT reverses the bits within a defined width, while bit shifts move them left or right.

For example, 12 AND 10 = 8, 12 OR 10 = 14, and 12 XOR 10 = 6. Enter these numbers in the calculator above to see their bit-by-bit results.

How to Use the Online Bitwise Calculator

  1. Choose an operation mode: Use the AND / OR / XOR tab to compare two numbers, or switch to Bit Shift / NOT for the other supported operations.
  2. Select Input Format: Choose the appropriate number format, such as decimal, binary, or hexadecimal.
  3. Choose Bit Width: Use the Bit Width dropdown to select the width for your calculation. The example shown in the tool uses 16-bit values.
  4. Enter your numbers: Type the first value into First Number (A) and the second into Second Number (B) for AND, OR, or XOR.
  5. Calculate: Select AND (&), OR (|), or XOR (^) for an individual operation. Select Calculate All to calculate all three together.
  6. Review the results: Examine the result cards, including the decimal value and its binary and hexadecimal representations.
  7. Inspect individual bits: Select a result card to view its bit diagram. Hover over or select a bit position to examine how the operation evaluates that position.
  8. Copy or reset: Use Copy Result for the selected output, Copy All Results for the group, or Reset Calculator to start again.

For shift or NOT operations, switch to the corresponding tab and use the controls presented in that mode. The selected width is particularly important when interpreting NOT results.

Bitwise AND, OR, and XOR: Worked Example

Consider the hexadecimal inputs shown in the calculator:

  • First Number (A): 0xC = 12 in decimal
  • Second Number (B): 0xA = 10 in decimal
  • Bit Width: 16-bit

The corresponding 16-bit binary values are:

A = 0000 0000 0000 1100
B = 0000 0000 0000 1010

Applying the three logical operations produces these results:

Operation Decimal Result Binary Result Hex Result
AND (&) 8 0000 0000 0000 1000 0x0008
OR (|) 14 0000 0000 0000 1110 0x000E
XOR (^) 6 0000 0000 0000 0110 0x0006

Notice that all three operations use the same input values. Only the logical rule changes. The interactive diagram makes this distinction visible at each bit position.

Understanding Bitwise Operators

Bitwise operators process individual bits instead of treating integers as ordinary arithmetic values. Each operator follows a particular rule, which determines the resulting binary pattern.

Bitwise AND Calculator (&)

Bitwise AND compares the corresponding bits of two integers. The result is 1 only when both bits are 1. Otherwise, the result is 0.

  1100  (12)
& 1010  (10)
  ----
  1000  (8)

Result: 12 & 10 = 8.

AND is especially useful for bitmask calculations. You can apply a mask to preserve particular bits while clearing others. For example, 0xAB & 0x0F produces 0x0B, isolating the lower four bits of the original value.

Bitwise OR Calculator (|)

Bitwise OR returns 1 when at least one of the two corresponding bits is 1. It returns 0 only when both bits are 0.

  1100  (12)
| 1010  (10)
  ----
  1110  (14)

Result: 12 OR 10 = 14.

OR is commonly used to set bits or combine flags. For instance, if the bits represent independent application permissions, OR can combine two permission masks without removing bits already enabled.

Bitwise XOR Calculator (^)

XOR means exclusive OR. It returns 1 when the corresponding bits are different and 0 when they are the same.

  1100  (12)
^ 1010  (10)
  ----
  0110  (6)

Result: 12 XOR 10 = 6.

XOR is useful for toggling specific bits, identifying differences between binary patterns, and implementing certain error-checking algorithms.

Another useful hexadecimal example is 0xFF ^ 0xAA = 0x55. XOR produces 1 wherever the bits in the two input values differ.

Bitwise AND, OR, and XOR Truth Table

The following truth table summarizes the three binary operations. A and B represent corresponding individual bits, not complete integers.

Bit A Bit B AND OR XOR
0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0

The key distinction is the final row: when both inputs are 1, AND and OR return 1, but XOR returns 0. This is why OR and XOR cannot be used interchangeably.

Bitwise NOT Calculator: Inverting Binary Bits

The bitwise NOT operator (~) flips each bit within the chosen representation. Every 0 becomes 1, and every 1 becomes 0. Unlike AND, OR, and XOR, NOT operates on one integer.

Consider the decimal value 12, represented as an unsigned 8-bit integer:

Value: 00001100  (12)
NOT:   11110011  (243)

In this 8-bit interpretation, NOT 12 equals 243, or 0xF3.

However, the width matters. The same operation using a 16-bit unsigned representation produces 1111111111110011, which is decimal 65523 (0xFFF3).

Unsigned fixed-width NOT formula:
NOT(A) = (2w – 1) XOR A
Where w is the bit width and A is a value within that unsigned range.

Programming languages may interpret the inverted pattern as a signed value, producing a different displayed decimal result. Always check bit width and signedness when comparing calculator output with program code.

Bit Shift Calculator: Left Shift and Right Shift

Bit shifting moves binary digits left or right by a specified number of positions. Shifts are commonly used in binary arithmetic, bitmask construction, and low-level programming.

Left Shift (<<)

A left shift moves the bits toward more significant positions. For a nonnegative integer without overflow, shifting left by one position multiplies its value by two.

5 in binary:      00000101
5 left shift 2:   00010100

5 << 2 = 20

Two left shifts are equivalent to multiplying by 2 squared (4), provided no significant bits are discarded by the chosen width.

Right Shift (>>)

A right shift moves the bits toward less significant positions. For nonnegative integers, shifting right by one position discards the lowest bit and produces the result of integer division by two.

20 in binary:     00010100
20 right shift 2: 00000101

20 >> 2 = 5

For negative numbers, right-shift behavior depends on whether the operation is arithmetic (sign-extending) or logical (zero-filling). The result may also depend on the programming language and selected bit width. Do not assume every implementation handles signed shifts identically.

Why Bit Width Matters in Bitwise Calculations

The Bit Width setting determines how many bit positions are considered in the operation. This is especially relevant for NOT and shifting operations, where the result can depend on the available number of bits.

For example, the same number can be represented with leading zeros at different widths:

8-bit:   00001100
16-bit:  0000000000001100
32-bit:  00000000000000000000000000001100

All three patterns represent decimal 12 when treated as unsigned integers. Their different widths become important when bits are inverted or shifted beyond the available range.

When calculating results for a specific data type, choose a width that matches the representation you are examining. Keep in mind that fixed-width arithmetic may discard bits that exceed the available positions.

Decimal, Binary, and Hexadecimal Bitwise Calculations

The input format determines how the calculator interprets the numbers you enter. The underlying bitwise operation works on binary values regardless of how you write the inputs.

Format Base Example of Decimal 12
Decimal 10 12
Binary 2 1100
Hexadecimal 16 0xC

Binary is useful when you want to inspect individual bits directly. Hexadecimal is a compact way to represent longer binary patterns because each hexadecimal digit corresponds to four bits. Decimal is convenient when working with ordinary integer values.

Always match your entry to the selected format. For example, 1010 represents decimal 10 in binary but decimal 1010 in base 10. Mixing formats can produce a valid calculation with an unintended result.

Explore the Interactive Binary Bit Diagram

One of the most useful parts of this online bitwise calculator is its visual breakdown. Instead of displaying only a numerical answer, the tool shows how individual input bits contribute to the selected result.

After calculating AND, OR, or XOR, select the result card you want to inspect. The bit diagram displays the positions alongside the binary values for A, B, and the result. You can hover over or select a bit position to examine the operation applied there.

This helps when an unexpected output comes from a single bit, especially in longer hexadecimal values. You can also scroll horizontally when the diagram extends beyond the visible area.

Practical Bitwise Calculation Examples

Example 1: Checking a Permission Bit with AND

Suppose an application uses three permission bits: READ = 4, WRITE = 2, and EXECUTE = 1. A permission value of 6 (binary 110) indicates READ and WRITE.

Permission value: 6  (110)
READ mask:        4  (100)

6 & 4 = 4

Because the result equals the READ mask, that permission bit is enabled.

To check EXECUTE:

6 & 1 = 0

A zero result means the EXECUTE bit is not enabled.

Example 2: Combining Flags with OR

Suppose a feature flags value is 4 (binary 0100). To enable the flag represented by 2 (binary 0010), use OR:

0100 | 0010 = 0110

4 | 2 = 6

The original flag remains set, and the additional flag becomes enabled.

Example 3: Toggling a Bit with XOR

Imagine a number with decimal value 5 (binary 0101). To toggle bit position 2, counting from zero at the right, use the mask 4:

0101 ^ 0100 = 0001

5 ^ 4 = 1

Applying the same mask again restores the original value:

0001 ^ 0100 = 0101

1 ^ 4 = 5

This makes XOR useful for switching an individual binary flag between 0 and 1.

Example 4: Extracting Bits from a Hexadecimal Value

Suppose you need the lower four bits of 0xAB. Apply the hexadecimal mask 0x0F:

  10101011  (0xAB)
& 00001111  (0x0F)
  --------
  00001011  (0x0B)

The result is 11 in decimal. The upper four bits have been cleared, leaving the lower four bits unchanged.

Who Can Use This Bitwise Operator Calculator?

Software developers can use the calculator to inspect binary flags, check masks, and compare logical expressions with expected results. When reviewing changed implementations, a separate Diff Checker can help compare code versions or copied output text.

Computer science students can examine AND, OR, XOR, NOT, and shifting while learning number systems, Boolean logic, and binary representations.

Embedded systems and IT professionals can use fixed-width examples when reasoning about status flags, register fields, or integer bit patterns. The selected width should always match the representation under examination.

Common Mistakes When Using a Bitwise Calculator

  • Choosing the wrong input format: Binary 1010 and decimal 1010 are different integers.
  • Ignoring bit width: NOT and shift calculations can change depending on how many bits are used.
  • Confusing AND with OR: AND requires both bits to be 1; OR needs at least one.
  • Confusing OR with XOR: XOR produces 0 when both input bits are 1.
  • Treating XOR as secure encryption: XOR is a logical operation, not a complete encryption system. For actual message protection, use a suitable authenticated encryption method rather than a simple XOR mask. Our Encrypt and Decrypt Text Tool covers separate text-encryption workflows.
  • Assuming shifts never overflow: Bits can be discarded when a result exceeds the chosen width.
  • Assuming signed and unsigned integers behave identically: The same bit pattern may represent different decimal values depending on its interpretation.

Tips for Checking Bitwise Results

Start with small numbers when testing an unfamiliar operator. A short binary pattern makes it easier to confirm every bit manually.

For hexadecimal values, remember that one hex digit corresponds to four binary bits. This makes it easier to align masks and recognize byte boundaries.

When working with a particular programming language, compare the same bit width and signedness. The calculator is useful for understanding the bit pattern, but language-specific integer rules may affect how a program displays or processes the value.

Limitations of Bitwise Calculations

Bitwise results depend on the supplied integers, selected operation, bit width, and how signed values are interpreted. Results from a fixed-width calculator should not automatically be treated as identical to every programming language’s integer behavior.

The calculator illustrates logical bit operations; it is not a replacement for debugging code that also involves data types, operator precedence, overflow, or language-specific conversions. For important implementations, verify the result against the exact rules of your target environment.

Calculate and Inspect Your Bitwise Results

Use the Bitwise Calculator above to test your next AND, OR, XOR, NOT, or shift operation. Select your input format and bit width, perform the calculation, and inspect the individual bits when you need to understand the result.

You can also explore our Calculator Tools for other numerical tasks.

Frequently Asked Questions

What is a bitwise calculator?

A bitwise calculator performs logical operations on individual bits within integer values. It is useful for operations such as AND, OR, XOR, NOT, and bit shifting, which are commonly used in programming and digital systems.

How do I calculate bitwise AND?

Convert both integers to binary, align their bits, and return 1 only at positions where both inputs contain 1. For example, 12 AND 10 produces 8 because binary 1100 AND 1010 equals 1000.

What is the difference between bitwise OR and XOR?

OR returns 1 when either or both corresponding bits are 1. XOR returns 1 only when the corresponding bits differ. For example, 12 OR 10 equals 14, while 12 XOR 10 equals 6.

How does the bitwise NOT operator work?

NOT flips each bit within a specified representation. For an unsigned 8-bit value, NOT 12 equals 243. With a 16-bit unsigned representation, the inverted pattern instead represents 65523. Signed integer interpretations may differ.

Can I calculate bitwise operations with hexadecimal values?

Yes. Select the hexadecimal input format and enter valid hexadecimal values, such as 0xC and 0xA. The calculator can display their logical results with decimal, binary, and hexadecimal representations.

What does bit width mean in a bitwise calculator?

Bit width is the number of binary positions used to represent a value for the calculation. It matters when performing NOT or shifts and when interpreting fixed-width results. Select a width consistent with the integer representation you are working with.

What is a bitmask, and how do I calculate one?

A bitmask is a binary pattern used to select or modify particular bits in another value. For example, applying 0x0F with AND preserves only the lower four bits of an integer. The calculator’s AND and OR operations can help test masking and flag-setting expressions.

Useful Developer & Text Utility Tools

If you are using the Bitwise Calculator, these related tools can help with code comparison, text encryption, formatting, and quick number-based utility tasks.