Cookies This site keeps only what it needs to work. There is no analytics and no advertising on it today, and nothing here follows you to other sites. Read the privacy policy

Choose what to allow
+92 312 8299940Free Quote
EN – Language: English
Free tool, nothing to install

Bitwise Calculator
AND, OR, XOR, NOT And Shifts On Your Bits

This bitwise calculator runs AND, OR, XOR, NAND, NOR, XNOR, NOT, shifts and rotates on 8, 16, 32 and 64 bit numbers. See each bit laid out in a row, with the result shown in decimal, hex, octal and binary.

  • FreePrice
  • 12Operations
  • NoneSign-up
  • NoneUploads

Bitwise Calculator

AND, OR, XOR, NOT, shifts and rotates on 8 to 64 bit numbers

The bits
 
The result in every form
Binary
—
Decimal
—
Signed decimal
—
Hexadecimal
—
Octal
—
Bits set to one
—

Ready. Type a number for A.

Your browser does all of the work here, in this tab. We upload nothing, store nothing and log nothing.
Add a link to this tool on your own site

Copy the code below and drop it into your page. It places a link to this free tool.

The short version

What A Bitwise Calculator Does For You

Computers store every number as bits, which are ones and zeros. Bitwise operations work on those bits one at a time. They are small, fast and everywhere in code.

The bits can be difficult to visualize, but. A bitwise calculator helps solve this problem. To use it, simply enter two numbers into the calculator. Next, select an operation. The bits will appear in a grid format, which makes it easy to find which bits have changed.

Also, you can type numbers in decimal, hex, binary or octal. So you can paste a mask from a datasheet or a flag from code, and get the answer in any form.

All parts of the validation run in your browser. So, anything you enter will remain in your computer.

How Bitwise Operations Work

A bitwise operation lines up two numbers and compares them bit by bit. AND puts a 1 in the result only where both inputs hold a 1. OR puts a 1 in the result wherever at least one input holds a 1. XOR puts a 1 in the result only where the two inputs disagree.

Drawing of two binary numbers stacked on the left and an arrow to the result row on the right
Two rows of bits become one.

So 12 AND 10 gives 8. In binary, 1100 AND 1010 gives 1000.

For more detail, see: Wikipedia article on bitwise operations.

Bitwise AND

First, AND keeps only the bits that are set in both numbers. Use it to read a flag or to apply a mask. For example, a value AND 0xFF keeps the lowest eight bits.

Bitwise OR

OR sets a bit if either number has it set. Also, use it to switch a flag on, or to combine two masks into one.

Bitwise XOR

A bit is set by XOR when the two bits are different. You can use this to change (flip) a bit, compare two numbers, or switch the order of two numbers without using a third number. When you XOR the same number twice, you get the first number back.

Bitwise calculator showing 12 XOR 10 in 8 bits with the bit rows and the result in every form
12 XOR 10 in 8 bits.

Then look at the bit rows in the tool. Each result bit sits under the two bits that made it.

NAND, NOR And XNOR

These three are the opposites of AND, OR and XOR. Each one runs the operation and then flips every bit. Chip designers love NAND and NOR, because either one can build every other gate.

Bitwise NOT

NOT swaps each 0 for a 1 and each 1 for a 0. In 8 bits, NOT 0 gives 255. So the width matters, and you should pick it first. In 32 bits, NOT 0 gives 4294967295.

Shift Left

A left shift pushes the bits up and fills the empty spots with zeros. One step to the left doubles an unsigned number. So 3 shifted left by 2 gives 12.

Bits that fall off the top are lost. Then the tool shows what remains.

Right Shifts: Logical Versus Arithmetic

A right shift moves the bits down. A logical shift puts zeros in at the top. An arithmetic shift copies the top bit instead, so a negative number stays negative.

Then one step to the right halves a number and rounds down.

Rotate Left And Right

A rotate moves the bits like a shift, but the bits that fall off one end return at the other. So nothing is lost. Also, hashes and ciphers use rotates a lot.

Choose The Width

Pick a width of 8, 16, 32 or 64 bits to match your code. The width sets how many bits NOT flips, where a shift loses bits, and how a number reads as signed.

A number too big for the width keeps only its lowest bits, and the tool tells you.

Signed And Unsigned Numbers

The same bits can stand for two different numbers. In 8 bits, 11111111 is 255 unsigned and -1 signed. Both are shown, so you can use the one your code relies on.

Negative inputs use the standard two's complement form.

Type Numbers In Binary, Octal, Decimal Or Hex

Choose decimal, hex, binary or octal for the box. You can also add a prefix, such as 0x for hex, 0b for binary and 0o for octal, and the prefix wins. Spaces and underscores do not count, so 1010 1111 works.

Common Uses

Programmers use bitwise operations for flags, masks, permissions, colour channels, packed data, hashes and fast maths. For example, a colour in 0xRRGGBB form keeps red in the top byte.

So shift right by 16 and AND with 0xFF to read it.

Check Your Code

Treat the tool as a way to double-check your work. Type the values from your code, run the same operation, and compare. So it helps you find an off by one shift or a wrong mask.

Safe By Design

First, every step runs inside your browser. No number you type is sent out or stored. So the numbers you work with stay private to you.

Video guide

How the Bitwise Calculator Works, Step by Step

This brief video shows each step from start to finish. Choose your language below, and switch on captions if they help.

How it works

Using The Bitwise Calculator, Step By Step

Four steps take you from two numbers to a result.

  • Pick the operation

    Choose AND, OR, XOR, NOT, a shift or a rotate.

  • Pick the width

    Choose 8, 16, 32 or 64 bits so it lines up with your code.

  • Type your numbers

    Use decimal, hex, binary or octal, with a prefix or without one.

  • Read the result

    See the bit rows, then copy the answer in the form you need.

Why this one

How This Bitwise Calculator Stands Out

It shows the bits, it matches real hardware, and it keeps your numbers private.

  • Twelve operations

    AND, OR, XOR, NAND, NOR, XNOR, NOT, three kinds of shift and two rotates.

  • Bits in rows

    See the bits of A, B and the result lined up together.

  • Real widths

    Work in 8, 16, 32 or 64 bits, just like a CPU does.

  • Exact 64 bit maths

    Big numbers stay exact, with no rounding.

  • Every base

    Type and read decimal, signed, hex, octal and binary.

  • Nothing leaves your tab

    Your browser works out every sum itself. Nobody on our side ever sees your numbers.

Good habits

Habits For Clean Bit Work

A few habits keep your bit maths right.

  • Pick the width first. NOT and shifts change with the width, so match your code.
  • Use hex for masks. Hex lines up with groups of four bits, so masks read easily.
  • Name your flags. Give each bit a name in your code, so a mask means something.
  • Use unsigned for bits. Signed numbers can surprise you on right shifts.
  • Mind the shift count. Shifting by the full width or more differs between languages.
  • Parenthesise. Bitwise operators rank below comparisons in many languages.
  • Test the edges. Try 0, the largest value and the top bit.
  • Check both readings. Look at the signed and the unsigned value of a result.
  • Write the mask out bit by bit in binary. A 0b prefix makes the intent clear.
  • Compare with your code. Run the same values here and in your program.
  • Keep it simple. A clear shift beats a clever trick that nobody can read.
Worth avoiding

Common Bitwise Mistakes This Tool Helps You Avoid

Each of these quietly breaks a mask.

  • Confusing AND with OR

    AND keeps shared bits, and OR gathers all of them.

  • Forgetting the width

    NOT 0 is 255 in 8 bits and far bigger in 32 bits.

  • Signed right shifts

    An arithmetic shift repeats the top bit, while a logical shift does not.

  • Shifting too far

    Bits shifted out are lost, and the count may wrap.

  • Logic instead of bitwise

    The && operator differs from &.

Questions

Bitwise Calculator Questions People Ask

Does this bitwise calculator cost anything?

Yes. You pay nothing, you need no account, and there’s no cap. Your browser does the heavy lifting, so we have no server bill to recover from you.

Do my numbers stay on my device?

No. Your browser works out every sum itself. Nothing reaches this site, and we keep nothing.

What exactly is a bitwise operation?

It is an operation that works on the individual bits of a number, instead of on its whole value.

What does a bitwise AND do to two numbers?

It gives a 1 in each place where both numbers have a 1. So 12 AND 10 gives 8.

What does a bitwise OR do to two numbers?

It gives a 1 in each place where at least one number has a 1. So 12 OR 10 gives 14.

What does a bitwise XOR do to two numbers?

It gives a 1 in each place where the two numbers differ. So 12 XOR 10 gives 6.

What does a bitwise NOT do to a number?

It flips every bit of one number. The result depends on the width, so pick 8, 16, 32 or 64 bits first.

What do NAND, NOR and XNOR mean?

They are AND, OR and XOR followed by a NOT. Each one flips every bit of the plain result.

What happens to the bits in a left shift?

It moves the bits up by the number of places you give, and fills the gap with zeros. Each step doubles an unsigned number.

How does a logical right shift differ from an arithmetic one?

A logical shift puts zeros in at the top. An arithmetic shift repeats the top bit, which keeps negative numbers negative.

What is a rotate?

A shift where the bits that fall off one end come back at the other end. No bit is lost.

Which bit width should I pick for my code?

Pick the width of the type in your code, such as 8 bits for a byte or 32 bits for an int.

What happens when a number is too large for the chosen width?

The calculator keeps the lowest bits that fit, and a note tells you it did so.

How does the calculator deal with negative numbers?

They use two's complement. In 8 bits, -1 becomes 11111111, which is 255 unsigned.

How do I type hex or binary?

Choose the base from the box, or type a prefix: 0x for hex, 0b for binary and 0o for octal.

How do I turn decimal into binary here?

Type the number in A, pick any operation such as OR with 0, and read the Binary card.

What is a bitmask?

A number whose set bits mark the bits you care about. You combine it with AND, OR or XOR.

How can I test whether one particular bit is set?

AND the number with a mask in which only that bit is 1. A result above zero means the bit is on.

How do I set, clear or toggle a bit?

Set it with OR and a mask. Clear it with AND and the NOT of the mask. Toggle it with XOR and the mask.

Can I swap two numbers with XOR?

Yes. XOR A with B, then B with A, then A with B again. The values trade places without a spare one.

Does the calculator cope with full 64-bit numbers?

Yes. It uses exact big integers, so 64 bit values stay precise with no rounding.

Can I copy the result in every base at once?

Yes. Pick a form in Copy as, such as hex or binary, and press Copy result.

Does it work on a phone too, or only on a desktop?

Yes. The fields stack and the bit rows scroll. So you can check bits on the go.

More free tools

Handy Companions For Low Level Work

Bit maths is one step. These three tools help with the rest.

Ready To Calculate Some Bits?

Pick an operation, type your numbers, and read the bits. This calculator is free, asks for no account and keeps every number on your device.

Prefer Denwix on GoogleReview Denwix on Google