NUMBER THEORYBinaryMathematics Calculator
โŠ•

Bitwise Operations

Bitwise operations work on each bit independently. AND, OR, XOR compare corresponding bits; NOT inverts all. Shifts move bits โ€” left multiplies by 2โฟ, right divides.

Concept Fundamentals
10
Operations
3
Shift Types
3
Formats
64
Max Bits

Did our AI summary help? Let us know.

IP subnet masks use AND: 192.168.1.5 & 255.255.255.0 = 192.168.1.0. XOR is reversible: (data ^ key) ^ key = data โ€” used in stream ciphers. NAND and NOR are universal gates โ€” any boolean function from them alone.

Key quantities
10
Operations
Key relation
3
Shift Types
Key relation
3
Formats
Key relation
64
Max Bits
Key relation

Ready to run the numbers?

Why: Bitwise ops map to single CPU instructions. IP subnet masks use AND; XOR is reversible for encryption.

How: Each operation applies to corresponding bit positions. Set: value | (1<<n). Clear: value & ~(1<<n). Toggle: value ^ (1<<n).

IP subnet masks use AND: 192.168.1.5 & 255.255.255.0 = 192.168.1.0.XOR is reversible: (data ^ key) ^ key = data โ€” used in stream ciphers.

Run the calculator when you are ready.

Start CalculatingAND, OR, XOR, NOT, NAND, NOR, XNOR, and bit shifts
โŠ•

Bitwise Calculator โ€” All Logic Operations

AND, OR, XOR, NOT, NAND, NOR, XNOR, and bit shifts. Binary, decimal, hex input.

Input Format

Operation

Operands

First operand required

For educational and informational purposes only. Verify with a qualified professional.

๐Ÿงฎ Fascinating Math Facts

๐ŸŒ

IP subnet masks use AND to identify network vs host portions.

โ€” RFC 791

๐Ÿ”

XOR is reversible: (data ^ key) ^ key = data โ€” used in encryption.

โ€” Cryptography

๐Ÿ“‹ Key Takeaways

  • โ€ข AND (&) โ€” Returns 1 only when both bits are 1. Use for masking and bit extraction.
  • โ€ข OR (|) โ€” Returns 1 if either bit is 1. Use for combining flags and setting bits.
  • โ€ข XOR (^) โ€” Returns 1 when bits differ. Use for toggling and parity checks.
  • โ€ข NOT (~) โ€” Inverts all bits. Use for complement and bit flipping.
  • โ€ข NAND โ€” NOT of AND. Universal gate; can build any logic circuit.
  • โ€ข NOR โ€” NOT of OR. Universal gate; used in memory cells.
  • โ€ข XNOR โ€” NOT of XOR. Returns 1 when bits are equal; equality check.
  • โ€ข Left shift (<<) multiplies by 2^n; right shift (>>) divides by 2^n.

๐Ÿ’ก Did You Know?

๐ŸŒIP subnet masks use AND to identify network vs host portions โ€” 192.168.1.5 & 255.255.255.0 = 192.168.1.0Source: RFC 791
๐ŸŽจRGB colors are packed/unpacked with shifts: red = (color >> 16) & 0xFF, green = (color >> 8) & 0xFFSource: Graphics Programming
๐Ÿ”XOR is reversible: (data ^ key) ^ key = data โ€” used in simple encryption and one-time padsSource: Cryptography
โšกLeft shift by 1 is faster than multiplying by 2 on most CPUs โ€” single instruction vs multiplySource: Computer Architecture
๐Ÿ“Unix file permissions: read=4, write=2, exec=1; read+write = 4|2 = 6; check with ANDSource: POSIX
๐Ÿ”ขCheck if bit n is set: (value & (1 << n)) !== 0. Fastest way to test a single bit.Source: Bit Manipulation
๐Ÿง NAND and NOR are universal gates โ€” any Boolean function can be built from only NAND or only NOR gatesSource: Digital Logic
๐Ÿ“กNetwork protocols use bitwise ops for header parsing, checksums, and protocol flagsSource: Networking

๐Ÿ“– How Bitwise Operations Work

Bitwise operations work on each bit independently. AND, OR, and XOR compare corresponding bits of two numbers; NOT inverts all bits of a single number. Shifts move bits left or right โ€” left shift fills with zeros; logical right shift fills with zeros; arithmetic right shift preserves the sign bit for signed integers.

Bit-by-Bit Processing

Each operation applies to corresponding bit positions. Example: 1010 & 1100 compares bit 0 with bit 0, bit 1 with bit 1, etc. Result: 1000 (only position 3 has both 1s).

๐ŸŽฏ Expert Tips

Set Bit

value |= (1 << n)

Clear Bit

value &= ~(1 << n)

Toggle Bit

value ^= (1 << n)

Check Bit

(value & (1 << n)) !== 0

โš–๏ธ Comparison Table โ€” All Operations

ABANDORXORNANDNORXNOR
00000111
01011100
10011100
11110001

โ“ Frequently Asked Questions

Why are bitwise ops faster than arithmetic?

They work at the hardware level in a single cycle. x << 1 is often faster than x * 2. No carry propagation for AND/OR/XOR.

Logical vs arithmetic right shift?

Logical (>>>) fills with 0s. Arithmetic (>>) preserves the sign bit for signed integers โ€” negative numbers stay negative.

What is a bitmask?

A pattern of bits to extract or manipulate specific bits. Example: (1 << 4) - 1 gives 0b1111 for lower 4 bits. Use AND to apply.

When to use bitwise operations?

Flags, networking (subnet masks), graphics (color packing), crypto (XOR cipher), embedded systems, performance-critical code.

What is NAND and why is it universal?

NAND = NOT(AND). You can build NOT, AND, OR, XOR from NAND alone. Same for NOR. Used in flash memory and logic design.

How does XNOR differ from XOR?

XNOR returns 1 when bits are equal (0,0 or 1,1). XOR returns 1 when bits differ. XNOR is useful for equality checks.

Can I use bitwise ops on floating-point?

In JavaScript, bitwise ops convert to 32-bit signed integers first. For floats, use typed arrays (Float32Array) and view as Int32.

What is the difference between & and &&?

& is bitwise AND (operates on each bit). && is logical AND (short-circuit, returns boolean). Use & for bit manipulation, && for conditions.

How do shifts handle overflow?

Left shift can overflow; JavaScript uses 32-bit for bitwise, so bits beyond 32 are lost. Right shift by โ‰ฅ32 gives 0 or -1 (arithmetic).

๐Ÿ“Š Infographic Stats

10
Operations
3
Shift Types
3
Input Formats
64
Max Bits

โš ๏ธ Disclaimer: Results assume fixed bit-width. JavaScript uses 32-bit signed integers for bitwise ops internally. For production use, verify behavior in your target language and platform. Not all operations may be available in every programming language.

๐Ÿ‘ˆ START HERE
โฌ…๏ธJump in and explore the concept!
AI

Related Calculators