Bitwise Operator Calculator

How this bitwise calculator works

Bitwise operators look abstract until you remember what they actually touch: not the whole number as a single block, but the individual bits inside it. This calculator lets you enter integers in decimal, binary, or hexadecimal form and then apply one of the classic low-level operations: AND, OR, XOR, NOT, left shift, or right shift. The result is shown immediately in three views so you can move between human-friendly decimal output and machine-friendly binary or hexadecimal output without doing conversions by hand.

That makes the tool useful in exactly the situations where bit patterns matter more than ordinary arithmetic. If you are checking permission flags, building masks, manipulating packed data, inspecting protocol fields, working with microcontrollers, debugging graphics formats, or simply learning why 5 ^ 3 is not the same as 5 | 3, you want to see the pattern as well as the final value. A decimal answer alone often hides the reason the operation behaved the way it did. Showing the binary form next to it exposes which bit positions changed, which stayed on, and which were discarded or shifted.

The most important first step is choosing the right input base. The base selector tells the calculator how to interpret both numbers. In decimal mode, entering 15 means fifteen. In binary mode, entering 15 would be invalid because binary allows only 0 and 1. In hexadecimal mode, entering FF means 255 in decimal. If you like, you can also include a matching prefix such as 0b1010 in base 2 or 0x1F in base 16. Negative values are allowed with a leading minus sign, which is handy when you want to inspect signed behavior.

What each input means

First Number is the main value being operated on. Second Number is used as the partner value for AND, OR, and XOR, and it becomes the shift distance for left and right shifts. The only exception is NOT, which uses the first number only and ignores the second field. That detail matters because many people expect NOT to produce an unsigned fixed-width result, but in JavaScript-style integer logic it behaves as a signed two's-complement inversion.

When you are learning bitwise logic, it helps to think in columns. Each binary digit is a yes-or-no switch for one power of two. The rightmost bit is the 1s place, then 2s, 4s, 8s, 16s, and so on. A bitwise operator compares or moves those columns directly. That is why the same decimal value can feel much easier to reason about once you rewrite it in binary.

Operator Plain-language meaning Quick example using 5 and 3
AND Keeps a 1 only where both numbers have a 1 in the same bit position. 0101 AND 0011 = 0001, so 5 AND 3 = 1.
OR Keeps a 1 wherever either number has a 1. 0101 OR 0011 = 0111, so 5 OR 3 = 7.
XOR Keeps a 1 where the bits are different and a 0 where they match. 0101 XOR 0011 = 0110, so 5 XOR 3 = 6.
NOT Flips every bit of the first number. For signed integers, NOT 5 becomes -6.
Left Shift Moves the first number's bits left by the second number of positions. 5 << 3 = 40 because 0101 becomes 101000.
Right Shift Moves the first number's bits right by the second number of positions. 5 >> 3 = 0 because 0101 becomes 0000.

Formula view: bitwise logic is column-by-column logic

Unlike a percentage calculator or a geometry formula, a bitwise calculator is not mainly about multiplication or division. Its core idea is positional logic. Each output bit depends on the corresponding input bit or bits. For AND, OR, and XOR, you can describe the result one position at a time. If ai and bi are the bits at position i, then the output bit follows the rule for the chosen operator.

ri = ai โˆง bi ri = ai โˆจ bi ri = ai โŠ• bi

Shifts are different because they move the whole pattern rather than comparing two columns. For nonnegative integers, a left shift by b positions is equivalent to multiplying by 2b, and a right shift is closely related to dividing by 2b and discarding the remainder. That shortcut is useful, but the true picture is still about bit positions sliding left or right.

a โ‰ช b = a ยท 2b a โ‰ซ b โ‰ˆ a 2b

The page also keeps two general MathML formulas below because they describe a broader pattern used by many calculators: inputs go into a function, and some algorithms can be thought of as weighted combinations of inputs. Bitwise logic is more specific than that general picture, but the general notation is still useful when you step back and describe the calculator as a mapping from input values to a result.

R = f ( x1 , x2 , โ€ฆ , xn ) T = โˆ‘ i=1 n wi ยท xi

Worked example with the default values

The form starts with 5 and 3, which is a good learning pair because the binary patterns are short and easy to compare. In binary, 5 is 0101 and 3 is 0011. Reading from right to left, compare the columns:

For AND, the only place where both numbers contain a 1 is the far-right bit. That gives 0001, which is 1 in decimal and 1 in hex. For OR, any column with at least one 1 survives, giving 0111, which is 7 in decimal. For XOR, matching bits become 0 and different bits become 1, so 0101 XOR 0011 = 0110, which is 6. Those three outputs are a fast sanity check: if your mental model says AND should be larger than OR in this example, you know you are mixing up the rules.

Now look at the shift operations. With the same default numbers, 5 << 3 moves the pattern 0101 three places left to become 101000, which equals 40 in decimal and 28 in hexadecimal. Meanwhile 5 >> 3 shifts the bits right three places, leaving 0. These shifts are often used when packing values into fields, creating masks, or extracting sections from a larger integer. They feel less mysterious once you watch the binary representation move.

NOT deserves its own warning because it is the operation most likely to surprise beginners. If you expect a neat 4-bit answer, you might think NOT 0101 should become 1010, which is 10. But JavaScript-style integer logic treats the value as a signed integer, so ~5 = -6. That is not a bug in the calculator. It is a reminder that signed two's-complement behavior and fixed-width textbook examples are related but not identical. If you are studying a fixed-width system such as an 8-bit register, mentally apply your own width when interpreting the inverted bits.

How to read the result panel

The result box shows the same value in three representations because each one answers a different question. Decimal is best when you want magnitude and quick comparison. Binary is best when you care about exact bit positions, masks, or operator behavior. Hexadecimal is compact and convenient once binary strings get long, because each hex digit corresponds to four binary bits. If you are checking a mask such as 0xF0, hex is often the cleanest way to think about it, while binary is best for teaching and debugging.

If the output is negative, the binary and hexadecimal strings are shown in signed form rather than padded to a fixed width. That makes the calculator honest about the underlying integer result, but it also means you should not read a negative binary string as if it were already an 8-bit or 32-bit register dump. For fixed-width hardware work, interpret the sign and width according to your target system.

Assumptions, limits, and good habits

This calculator works with integers only. Fractions do not belong in bitwise operators, so values such as 3.5 are not accepted. It also checks that your digits make sense for the selected base: binary accepts only 0 and 1, hexadecimal accepts 0 through 9 and A through F, and decimal accepts ordinary base-10 digits. If you switch the base selector, reread your input before computing because the same character string can represent a completely different value in another base.

Another good habit is to decide whether you care about mathematical value, signed interpretation, or fixed-width storage. Those are related ideas, but they are not always interchangeable. A result can be perfectly correct as a signed integer and still look strange if you expected an 8-bit mask. Likewise, right shift on negative numbers preserves the sign in arithmetic shifting, which may differ from an unsigned logical shift you have seen in another language. This calculator is excellent for learning and quick checks, but the right interpretation still depends on the environment you are targeting.

In short, use this tool as both a calculator and a visual translator. Enter your numbers in the right base, choose the operator deliberately, then inspect the decimal, binary, and hexadecimal views together. That three-way comparison is what turns a mysterious symbol such as XOR or NOT into something concrete and predictable.

Calculator inputs

Choose the base first, then enter both integers in that base. The second number is ignored for NOT and used as the shift count for left and right shift.

Enter numbers and choose an operation.

Tip: the NOT operator can return a negative number because the calculator follows signed integer bitwise behavior. For example, NOT 5 becomes -6, even though a fixed-width classroom example might show an unsigned bit pattern such as 1010.

Mini-game: Bit Gate Rush

This optional mini-game turns the same idea into a quick reflex puzzle. A target output pattern drops toward a bank of logic gates. Your job is to tap the operator that transforms A and B into that target before the signal packet reaches the bottom. Early rounds use AND, OR, and XOR; then NOT comes online; then the shift gates unlock and the layout starts shuffling. It is a fast way to build intuition for what each operator actually does instead of memorizing names.

Score0
Time75
Streak0
Wave1
Best0

Bit Gate Rush

Route each signal by choosing the operator that turns A and B into the target output. Tap a gate on the canvas or press the matching number key. Correct answers build streak and score; misses and wrong picks cost time.

Mission: survive 75 seconds. New gates unlock mid-run, so the puzzle starts readable and then gets deliciously busy.

Best score is saved on this device. Educational takeaway: AND keeps shared 1 bits, OR combines 1 bits, XOR highlights differences, NOT flips bits, and shifts move the whole pattern.

Mobile tip: tap the glowing gate cards. Keyboard fallback: press 1 through 6 to pick the visible gate in that slot. The game is separate from the calculator result, so feel free to use it as practice between calculations.

Embed this calculator

Copy and paste the HTML below to add the Bitwise Operator Calculator | AND, OR, XOR, NOT & Shift in Binary, Decimal, Hex to your website.