Bitwise Calculator
AND, OR, XOR, NOT and left/right shifts on two integers, shown in decimal, 32-bit two's-complement binary and hex, with every operation compared side by side.
Bitwise Calculator: with the default inputs, result is 8.
Ignored by NOT and by the shift operations.
Number of bit positions to shift. Only used by the shift operations.
- Expression
- 202 & 60 = 8
- Result in binary (32-bit)
- 00000000 00000000 00000000 00001000
- Result in hex
- 0x00000008
- a in binary
- 00000000 00000000 00000000 11001010
- b in binary
- 00000000 00000000 00000000 00111100
Assumptions
- All operations use 32-bit signed two's-complement integers, matching C, Java, C# and JavaScript.
- Shift counts are limited to 0–31; larger counts wrap modulo 32 in real code and are rejected here.
- The unsigned right shift produces a value in 0 … 4,294,967,295, so it can exceed the signed 32-bit maximum.
| Operation | Decimal | Binary (32-bit) | Hex |
|---|---|---|---|
| a AND b (a & b) | 8 | 00000000 00000000 00000000 00001000 | 0x00000008 |
| a OR b (a | b) | 254 | 00000000 00000000 00000000 11111110 | 0x000000FE |
| a XOR b (a ^ b) | 246 | 00000000 00000000 00000000 11110110 | 0x000000F6 |
| NOT a (~a) | -203 | 11111111 11111111 11111111 00110101 | 0xFFFFFF35 |
| a shifted left (a << n) | 808 | 00000000 00000000 00000011 00101000 | 0x00000328 |
| a shifted right, signed (a >> n) | 50 | 00000000 00000000 00000000 00110010 | 0x00000032 |
| a shifted right, unsigned (a >>> n) | 50 | 00000000 00000000 00000000 00110010 | 0x00000032 |
| a bit | b bit | AND | OR | XOR |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 1 |
| 1 | 0 | 0 | 1 | 1 |
| 1 | 1 | 1 | 1 | 0 |
AND keeps a bit only when both inputs have it; OR keeps it when either does; XOR keeps it when exactly one does.
How this is worked out
The formula
a & b bit is 1 when both bits are 1 (masking: keep selected bits) a | b bit is 1 when either bit is 1 (setting bits) a ^ b bit is 1 when exactly one bit is 1 (toggling bits; a ^ b ^ b = a) ~a every bit flipped; equals −a − 1 in two's complement a << n shift left n places = a × 2ⁿ (bits shifted off the top are lost) a >> n arithmetic shift right, sign bit copied = ⌊a ÷ 2ⁿ⌋ a >>> n logical shift right, zeros pulled in, result treated as unsigned
Open How it’s calculated above to see this worked through with your own numbers.
What you enter
- Operation
- Choose one of 7 options.a AND b (a & b) · a OR b (a | b) · a XOR b (a ^ b) · NOT a (~a) · a shifted left (a << n) · a shifted right, signed (a >> n) · a shifted right, unsigned (a >>> n)
- First integer (a)
- A number.from -2147483648 to 2147483647 · whole numbers only · defaults to 202
- Second integer (b)
- Ignored by NOT and by the shift operations.from -2147483648 to 2147483647 · whole numbers only · defaults to 60
- Shift amount
- Number of bit positions to shift. Only used by the shift operations.from 0 to 31 · whole numbers only · defaults to 2
What you get back
- Resultmain answer
- Expression
- Result in binary (32-bit)
- Result in hex
- a in binary
- b in binary
What this assumes
- All operations use 32-bit signed two's-complement integers, matching C, Java, C# and JavaScript.
- Shift counts are limited to 0–31; larger counts wrap modulo 32 in real code and are rejected here.
- The unsigned right shift produces a value in 0 … 4,294,967,295, so it can exceed the signed 32-bit maximum.
About this calculator
Bitwise operators work on the individual binary digits of an integer rather than on its value. They are how flags are packed into a single number, how colours are unpacked from a hex code, how permission bits are tested, and how hash functions stir their state.
How to use it
Enter two integers, pick an operation, and read the result in decimal, binary and hex. The comparison table shows every operation applied to the same pair at once, which is usually the fastest way to see what a mask is doing.
Binary is displayed as a full 32-bit two's-complement word, grouped into bytes. That is exactly how these operators behave in C, Java, JavaScript, C# and Go for 32-bit integers, so what you see here is what your program will do.
What each operator is for
- AND is masking. x & 0xFF keeps the low byte and discards everything above it. x & 1 tests whether x is odd.
- OR sets bits. flags | WRITE turns the write bit on without disturbing the others.
- XOR toggles bits, and it is its own inverse: x ^ k ^ k is x again. That property makes it the backbone of checksums, simple ciphers and the classic swap-without-a-temporary trick.
- NOT flips every bit. In two's complement, ~a is exactly −a − 1 — which is why ~0 is −1 rather than some large positive number.
- Shifts multiply and divide by powers of two. a << 3 is a × 8; a >> 3 is a ÷ 8 rounded towards negative infinity, which is not the same as truncation for negative numbers.
Two's complement, and where it bites
The top bit of a 32-bit signed integer carries the sign, and negative numbers are stored as the complement of their magnitude plus one. Three consequences catch people out:
- Left shifts overflow silently. Bits pushed past bit 31 are gone, so a << n stops equalling a × 2ⁿ once the value gets large. The calculator warns when that has happened.
- >> and >>> differ for negatives. The signed shift copies the sign bit, so −8 >> 1 is −4. The unsigned shift pulls in zeros, so −8 >>> 1 is 2,147,483,644.
- Shift counts wrap. a << 32 is a << 0 = a, because the count is taken modulo 32. The input is capped at 31 here to stop that being a silent surprise.
If you need bit patterns wider than 32 bits, use a language's 64-bit integer type or arbitrary-precision integers; the operators behave the same way, just with more room.
Frequently asked questions
▸What does the & operator do?
It compares two numbers bit by bit and keeps a 1 only where both have a 1. It is used to mask — to isolate a specific group of bits and zero out the rest.
▸Why is ~5 equal to −6?
In two's complement, flipping every bit of x gives −x − 1. That is a property of the representation, not a quirk of any one language.
▸What is the difference between >> and >>>?
The signed shift >> copies the sign bit into the top, so negatives stay negative. The unsigned shift >>> pulls in zeros and treats the result as an unsigned 32-bit value, so negatives become large positives.
▸Is left-shifting the same as multiplying by 2?
Yes, until it overflows. Once a 1 bit is pushed past bit 31 it is discarded, and the result no longer equals a × 2ⁿ. The calculator flags that case.
▸Why 32 bits and not 64?
Because that is what the bitwise operators in C, Java, JavaScript and C# use for their default integer type. Showing anything else would give you an answer your code would not reproduce.
Put this calculator on your own site
A working bitwise, free for any site, with no ads and no sign-up. It resizes to fit wherever you paste it and updates itself as this page improves.
Paste this anywhere. It works on any site, carries no ads, never expires, and always shows the current version.
Bitwise Calculator by CalculateItNow
The page's own title. The clearest description of what the link leads to.
The credit line sits outside the widget on purpose, so it is a real link on your page rather than one buried in a frame. Please keep it — it is what pays for CalculateItNow staying free and ad-free. The script only resizes the widget to fit its contents; drop it and the widget still works.
Browse every calculator widget·How to add it to WordPress, Squarespace or Wix
Related calculators
The questions people ask next to a bitwise.
Convert between binary, octal, decimal and hexadecimal with the repeated-division working and the place-value table shown, exact to 2^53.
a mod b with the quotient and remainder, showing where the mathematical modulo and the % operator in C, Java and JavaScript disagree on negative numbers.
Convert bits, bytes, KB, MB, GB and TB — and the binary KiB, MiB, GiB, TiB — and see why a 1 TB drive shows up as 931 GB. Decimal vs binary explained.
Raise any base to any power — negative, fractional or huge — with the expanded multiplication, scientific notation and the rule that applies shown.