bitwise operators calculator

Bitwise Operators Calculator

Compute AND, OR, XOR, NOT, and bit shifts instantly. Inputs accept decimal values, or prefixed values like 0b1011, 0x2F, and 0o17.

For shift operations, only the lower 5 bits of B are used (0–31), matching JavaScript behavior.
Enter your numbers and click Calculate.

What Is a Bitwise Operator?

A bitwise operator works directly on binary digits (bits). Instead of treating numbers as whole decimal values, bitwise operations compare or transform each bit position. This is incredibly useful for low-level programming tasks, flags, permissions, masking, and performance-oriented logic.

For example, the number 13 is 1101 in binary and 10 is 1010. A bitwise AND compares each bit:

1101   (13)
1010   (10)
----
1000   (8)

How to Use This Bitwise Calculator

  • Enter Number A and, when needed, Number B.
  • Choose a bitwise operation from the dropdown.
  • Click Calculate to view:
    • signed 32-bit result
    • unsigned 32-bit result
    • 32-bit binary representation
    • hexadecimal representation

You can type values in different formats:

  • Decimal: 25, -7
  • Binary: 0b11001
  • Hex: 0x19
  • Octal: 0o31

Bitwise Operators Explained

AND (&)

Returns 1 only when both bits are 1. Great for masking specific bits in a number.

OR (|)

Returns 1 if at least one bit is 1. Useful when turning feature flags on.

XOR (^)

Returns 1 when bits are different. Handy for toggling bits or quick equality-style bit checks.

NOT (~)

Inverts every bit: 1 becomes 0 and 0 becomes 1. In two's complement integer math, ~x equals -(x + 1).

Left Shift (<<)

Shifts bits left, filling with zeros on the right. This often acts like multiplying by powers of two, as long as overflow is not an issue.

Right Shift (>> and >>>)

  • >> is signed right shift and preserves the sign bit.
  • >>> is unsigned right shift and fills from the left with zeros.

Important JavaScript Behavior (32-bit integers)

JavaScript numbers are floating-point internally, but bitwise operators convert operands to 32-bit integers first. That means:

  • Results wrap into 32-bit range.
  • Negative values use two's complement.
  • Shift counts are effectively modulo 32.

This calculator follows exactly that same behavior, so the result matches what you'd get in JavaScript code.

Practical Use Cases

  • Permissions: read/write/execute flags combined into one integer.
  • Networking: subnet masks and protocol bit fields.
  • Graphics: channel packing (ARGB/RGBA).
  • Performance: quick integer tricks in loops or parsers.
  • Embedded systems: hardware register manipulation.

Common Mistakes to Avoid

  • Confusing logical operators (&&, ||) with bitwise operators (&, |).
  • Forgetting that bitwise operations in JS use signed 32-bit behavior.
  • Assuming >> and >>> are the same for negative numbers.
  • Not masking when only certain bits should be inspected.

Quick Bitwise Cheat Sheet

A & B     // AND
A | B     // OR
A ^ B     // XOR
~A        // NOT
A << n    // Left shift
A >> n    // Signed right shift
A >>> n   // Unsigned right shift

If you frequently work with binary operations, keep this page bookmarked. A fast bitwise operators calculator can save time, reduce mistakes, and make debugging dramatically easier.

🔗 Related Calculators