Skip to main content

Bitwise Calculator

Calculate bitwise instantly with our math tool. Shows detailed work, formulas used, and multiple solution methods. See charts, tables, and visual results.

Skip to calculator
Mathematics

Bitwise Calculator

Perform AND, OR, XOR, NOT, NAND, NOR, and XNOR bitwise operations. View binary, hexadecimal, and decimal results with Hamming distance and population count.

Last updated: December 2025Reviewed by NovaCalculator Mathematics Team

Calculator

Adjust values & calculate
A = 1700xAA | popcount: 4
10101010
B = 850x55 | popcount: 4
01010101
AND (&)1 only if both bits are 1
0
00000000
Hex: 0x00
OR (|)1 if either bit is 1
255
11111111
Hex: 0xFF
XOR (^)1 if bits differ
255
11111111
Hex: 0xFF
NAND (~&)NOT of AND
-1
11111111
Hex: 0xFF
NOR (~|)NOT of OR
-256
00000000
Hex: 0x00
XNOR (~^)1 if bits are same
-256
00000000
Hex: 0x00
NOT A (~A)
-171
01010101
NOT B (~B)
-86
10101010
Hamming Distance
8
Number of bit positions where A and B differ
Your Result
170 AND 85 = 0 | OR = 255 | XOR = 255 | Hamming = 8
Share Your Result
Understand the Math

Formula

AND: 1&1=1 | OR: 1|0=1 | XOR: 1^0=1 | NOT: ~0=1

Bitwise operations apply logical functions to each pair of corresponding bits independently. AND produces 1 only when both bits are 1. OR produces 1 when at least one bit is 1. XOR produces 1 when bits are different. NOT flips every bit.

Last reviewed: December 2025

Worked Examples

Example 1: Bitwise AND for Subnet Masking

Apply subnet mask 255.255.255.0 to IP address 192.168.5.137 using bitwise AND.
Solution:
IP: 11000000.10101000.00000101.10001001 (192.168.5.137) Mask: 11111111.11111111.11111111.00000000 (255.255.255.0) AND: 11000000.10101000.00000101.00000000 (192.168.5.0) Network address: 192.168.5.0 Host part: 137 (from IP AND NOT mask) Broadcast: 192.168.5.255 (network OR NOT mask)
Result: Network: 192.168.5.0 | Host: 137 | Broadcast: 192.168.5.255

Example 2: XOR for Simple Encryption

Encrypt the value 170 (binary 10101010) using XOR with key 85 (binary 01010101), then decrypt.
Solution:
Original: 10101010 (170) Key: 01010101 (85) Encrypted: 11111111 (255) [170 XOR 85] Decrypt: 11111111 XOR 01010101 = 10101010 (170) The original value is restored by XOR-ing with the same key. Hamming distance between 170 and 85: 8 (all bits differ)
Result: Encrypted: 255 | Decrypted: 170 | Hamming Distance: 8
Expert Insights

Background & Theory

The Bitwise Calculator applies the following established principles and formulas. Mathematics rests on a hierarchy of number systems, each extending the previous. The natural numbers (1, 2, 3, ...) support counting and ordering. The integers add negative values and zero, enabling subtraction without restriction. The rational numbers, expressible as p/q where p and q are integers and q is nonzero, close the system under division. The real numbers fill the gaps left by irrationals such as the square root of 2 or pi, forming a complete ordered field. The complex numbers, written as a + bi where i is the square root of negative one, complete the algebraic closure of the reals and allow every polynomial to have a root. Prime factorization states that every integer greater than one is uniquely expressible as a product of primes, a result known as the Fundamental Theorem of Arithmetic. Computing the greatest common divisor (GCD) of two integers relies most efficiently on the Euclidean algorithm: repeatedly replace the larger number with the remainder when it is divided by the smaller, until the remainder is zero. The last nonzero remainder is the GCD. The least common multiple (LCM) follows from the identity LCM(a, b) = |a * b| / GCD(a, b). Modular arithmetic defines equivalence classes of integers that share the same remainder under division by a modulus n. Fermat's Little Theorem and Euler's Theorem arise from this structure and underpin modern cryptography. Logarithms are the inverses of exponential functions. If b raised to the power x equals y, then the logarithm base b of y equals x. The natural logarithm uses base e, approximately 2.71828. Combinatorics counts arrangements and selections. The number of ordered arrangements (permutations) of r objects from n distinct objects is nPr = n! / (n - r)!. The number of unordered selections (combinations) is nCr = n! / (r! * (n - r)!). Pascal's triangle arranges these binomial coefficients so that each entry equals the sum of the two entries directly above it. The Fibonacci sequence, defined by F(1) = 1, F(2) = 1, and F(n) = F(n-1) + F(n-2), appears throughout nature and connects deeply to the golden ratio via Binet's formula.

History

The history behind the Bitwise Calculator traces back through the following developments. Mathematics as a systematic discipline traces to ancient Mesopotamia. Babylonian clay tablets dating to around 1800 BCE demonstrate knowledge of quadratic equations, Pythagorean triples, and base-60 arithmetic, suggesting a practical mathematical tradition far preceding Greek formalism. Euclid of Alexandria compiled the Elements around 300 BCE, establishing the axiomatic method that would define rigorous mathematics for over two thousand years. His work organized plane geometry, number theory, and proportion into logically chained propositions derived from a small set of postulates. The algorithm bearing his name for computing GCDs appears in Book VII and remains in use today. In the 9th century, the Persian scholar Muhammad ibn Musa Al-Khwarizmi wrote Al-Kitab al-mukhtasar fi hisab al-jabr wal-muqabala, the treatise whose title gave algebra its name. He systematized the solution of linear and quadratic equations and described procedures that operated on unknowns as objects, a conceptual leap away from purely numerical calculation. Rene Descartes introduced coordinate geometry in 1637 by uniting algebra and Euclidean geometry, allowing curves to be studied through equations. This synthesis set the stage for calculus. Isaac Newton and Gottfried Wilhelm Leibniz independently developed calculus during the 1660s and 1670s, triggering a priority dispute that lasted decades and divided British and Continental mathematicians. Carl Friedrich Gauss proved the Fundamental Theorem of Algebra in 1799, showing that every nonconstant polynomial has at least one complex root. His Disquisitiones Arithmeticae of 1801 established modern number theory. David Hilbert's formalist program at the turn of the 20th century sought to place all of mathematics on an explicit axiomatic foundation, a project that Kurt Godel's incompleteness theorems of 1931 showed to be fundamentally limited. Alan Turing's work in the 1930s on computability introduced the theoretical model of the stored-program computer and linked mathematical logic directly to the limits of algorithmic calculation. His proof that no algorithm can decide in general whether an arbitrary program will halt or run forever placed fundamental boundaries on what mathematics can mechanically determine, and it opened the discipline now known as theoretical computer science.

Key Features

  • Convert integers and large numbers between binary (base 2), octal (base 8), decimal (base 10), and hexadecimal (base 16) with all four representations displayed side by side for direct comparison.
  • Simulate bitwise operations including AND, OR, XOR, NOT, left shift, and right shift on integer operands, showing binary input and output at each step to clarify the logic.
  • Convert Roman numerals to Arabic numerals and vice versa for values from 1 to 3,999,999, validating correct subtractive notation and flagging malformed input.
  • Express any real number in scientific notation and convert between standard and scientific forms, with control over the number of significant figures and rounding behavior.
  • Inspect the IEEE 754 binary representation of single-precision and double-precision floating-point numbers, displaying sign bit, exponent, and mantissa fields to aid debugging.
  • Calculate common checksums and parity bits including even and odd parity, Luhn algorithm results, and simple modular sums used in data transmission and barcode validation.
  • Factorize integers into their prime components and perform primality testing using trial division and Miller-Rabin methods, handling numbers up to 15 digits.
  • Spell out any integer as words in multiple languages including English, Spanish, French, and German, supporting ordinal forms and values from zero up into the trillions.

Share this calculator

Explore More

Frequently Asked Questions

Bitwise operations manipulate individual bits within binary numbers, performing logical operations on each pair of corresponding bits independently. At the hardware level, these operations are implemented using logic gates: AND gates, OR gates, XOR gates, and NOT gates (inverters). When you compute A AND B, each bit position is processed by a separate AND gate simultaneously, making bitwise operations among the fastest instructions a CPU can execute (typically one clock cycle). A modern 64-bit CPU processes all 64 bits in parallel. These operations form the foundation of all digital computing, from simple arithmetic to complex encryption algorithms. Understanding bitwise operations gives insight into how computers actually process information at the most fundamental level.
Bitwise AND compares each bit pair and produces 1 only when BOTH bits are 1; otherwise it produces 0. The truth table is: 0 AND 0 = 0, 0 AND 1 = 0, 1 AND 0 = 0, 1 AND 1 = 1. The most common use of AND is bit masking, where you use a mask to extract specific bits from a value. For example, to check if bit 3 is set: value AND 8 (binary 1000). If the result is non-zero, bit 3 is set. AND is also used to clear specific bits: value AND (NOT mask) zeros out the bits specified by the mask while preserving all others. In networking, subnet masks use AND to separate network and host portions of IP addresses. These bit manipulation techniques are fundamental to systems programming.
Bitwise OR compares each bit pair and produces 1 when EITHER or BOTH bits are 1; it produces 0 only when both bits are 0. The truth table is: 0 OR 0 = 0, 0 OR 1 = 1, 1 OR 0 = 1, 1 OR 1 = 1. OR is primarily used to SET specific bits without affecting others. For example, to turn on bit 5: value OR 32 (binary 100000). This guarantees bit 5 will be 1 while leaving all other bits unchanged. OR is widely used in flag-based systems where multiple boolean options are packed into a single integer. For instance, file permissions in Unix use OR to combine read (4), write (2), and execute (1) flags: rwx = 4 OR 2 OR 1 = 7. Graphics programming uses OR to combine color channels and overlay bitmap images.
XOR (exclusive OR) produces 1 when the bits are DIFFERENT and 0 when they are the SAME. The truth table is: 0 XOR 0 = 0, 0 XOR 1 = 1, 1 XOR 0 = 1, 1 XOR 1 = 0. XOR is unique because it is its own inverse: A XOR B XOR B = A, meaning XOR-ing with the same value twice restores the original. This property makes XOR essential in cryptography for simple encryption/decryption, in RAID storage systems for parity calculation, and in error-detecting codes. XOR can toggle specific bits without knowing their current state: value XOR mask flips the bits in the mask positions. The classic programming trick of swapping two variables without a temporary uses XOR: a ^= b; b ^= a; a ^= b.
Bitwise NOT (complement) flips every bit: 0 becomes 1 and 1 becomes 0. For an n-bit unsigned number, NOT x = 2^n - 1 - x. In two's complement signed representation, NOT x = -(x + 1), which is a key identity. For example, NOT 0 = -1 (all bits become 1), NOT 5 = -6, and NOT -1 = 0. This relationship is used to compute two's complement negation: -x = NOT x + 1. NOT is used in combination with AND to clear bits (AND NOT mask), and with other operators to create NAND, NOR, and XNOR operations. In hardware, the NOT gate (inverter) is the simplest logic gate and is fundamental to the construction of all other gates. Understanding NOT is essential for working with complement arithmetic and signed number representations.
Flag systems pack multiple boolean values into a single integer, using each bit as a separate on/off switch. Common examples include Unix file permissions (read=4, write=2, execute=1), window style flags in GUI programming, and feature flags in configuration systems. To check a flag: (value AND flag) != 0. To set a flag: value = value OR flag. To clear a flag: value = value AND (NOT flag). To toggle a flag: value = value XOR flag. This approach is memory-efficient (32 flags in one integer versus 32 separate booleans) and fast (all flag operations are single CPU instructions). Database systems often use bit flags for storing multiple boolean attributes in a single column, significantly reducing storage requirements.
Educational Note: This calculator is provided for educational and informational purposes. Results are based on the formulas and inputs provided. Always verify important calculations independently. NovaCalculator processes calculator inputs client-side; optional analytics follow visitor consent settings.Reviewed by: NovaCalculator Mathematics TeamVerified against standard mathematical and scientific references. Last reviewed: December 2025. © 2024–2026 NovaCalculator.

Share this calculator

Formula

AND: 1&1=1 | OR: 1|0=1 | XOR: 1^0=1 | NOT: ~0=1

Bitwise operations apply logical functions to each pair of corresponding bits independently. AND produces 1 only when both bits are 1. OR produces 1 when at least one bit is 1. XOR produces 1 when bits are different. NOT flips every bit.

Worked Examples

Example 1: Bitwise AND for Subnet Masking

Problem: Apply subnet mask 255.255.255.0 to IP address 192.168.5.137 using bitwise AND.

Solution: IP: 11000000.10101000.00000101.10001001 (192.168.5.137)\nMask: 11111111.11111111.11111111.00000000 (255.255.255.0)\nAND: 11000000.10101000.00000101.00000000 (192.168.5.0)\n\nNetwork address: 192.168.5.0\nHost part: 137 (from IP AND NOT mask)\nBroadcast: 192.168.5.255 (network OR NOT mask)

Result: Network: 192.168.5.0 | Host: 137 | Broadcast: 192.168.5.255

Example 2: XOR for Simple Encryption

Problem: Encrypt the value 170 (binary 10101010) using XOR with key 85 (binary 01010101), then decrypt.

Solution: Original: 10101010 (170)\nKey: 01010101 (85)\nEncrypted: 11111111 (255) [170 XOR 85]\n\nDecrypt: 11111111 XOR 01010101 = 10101010 (170)\nThe original value is restored by XOR-ing with the same key.\n\nHamming distance between 170 and 85: 8 (all bits differ)

Result: Encrypted: 255 | Decrypted: 170 | Hamming Distance: 8

Frequently Asked Questions

What are bitwise operations and how do they work at the hardware level?

Bitwise operations manipulate individual bits within binary numbers, performing logical operations on each pair of corresponding bits independently. At the hardware level, these operations are implemented using logic gates: AND gates, OR gates, XOR gates, and NOT gates (inverters). When you compute A AND B, each bit position is processed by a separate AND gate simultaneously, making bitwise operations among the fastest instructions a CPU can execute (typically one clock cycle). A modern 64-bit CPU processes all 64 bits in parallel. These operations form the foundation of all digital computing, from simple arithmetic to complex encryption algorithms. Understanding bitwise operations gives insight into how computers actually process information at the most fundamental level.

How does the bitwise AND operation work and what is it used for?

Bitwise AND compares each bit pair and produces 1 only when BOTH bits are 1; otherwise it produces 0. The truth table is: 0 AND 0 = 0, 0 AND 1 = 0, 1 AND 0 = 0, 1 AND 1 = 1. The most common use of AND is bit masking, where you use a mask to extract specific bits from a value. For example, to check if bit 3 is set: value AND 8 (binary 1000). If the result is non-zero, bit 3 is set. AND is also used to clear specific bits: value AND (NOT mask) zeros out the bits specified by the mask while preserving all others. In networking, subnet masks use AND to separate network and host portions of IP addresses. These bit manipulation techniques are fundamental to systems programming.

What is the bitwise OR operation and when should you use it?

Bitwise OR compares each bit pair and produces 1 when EITHER or BOTH bits are 1; it produces 0 only when both bits are 0. The truth table is: 0 OR 0 = 0, 0 OR 1 = 1, 1 OR 0 = 1, 1 OR 1 = 1. OR is primarily used to SET specific bits without affecting others. For example, to turn on bit 5: value OR 32 (binary 100000). This guarantees bit 5 will be 1 while leaving all other bits unchanged. OR is widely used in flag-based systems where multiple boolean options are packed into a single integer. For instance, file permissions in Unix use OR to combine read (4), write (2), and execute (1) flags: rwx = 4 OR 2 OR 1 = 7. Graphics programming uses OR to combine color channels and overlay bitmap images.

How does XOR work and why is it special among bitwise operations?

XOR (exclusive OR) produces 1 when the bits are DIFFERENT and 0 when they are the SAME. The truth table is: 0 XOR 0 = 0, 0 XOR 1 = 1, 1 XOR 0 = 1, 1 XOR 1 = 0. XOR is unique because it is its own inverse: A XOR B XOR B = A, meaning XOR-ing with the same value twice restores the original. This property makes XOR essential in cryptography for simple encryption/decryption, in RAID storage systems for parity calculation, and in error-detecting codes. XOR can toggle specific bits without knowing their current state: value XOR mask flips the bits in the mask positions. The classic programming trick of swapping two variables without a temporary uses XOR: a ^= b; b ^= a; a ^= b.

What is the bitwise NOT operation and how does it relate to two's complement?

Bitwise NOT (complement) flips every bit: 0 becomes 1 and 1 becomes 0. For an n-bit unsigned number, NOT x = 2^n - 1 - x. In two's complement signed representation, NOT x = -(x + 1), which is a key identity. For example, NOT 0 = -1 (all bits become 1), NOT 5 = -6, and NOT -1 = 0. This relationship is used to compute two's complement negation: -x = NOT x + 1. NOT is used in combination with AND to clear bits (AND NOT mask), and with other operators to create NAND, NOR, and XNOR operations. In hardware, the NOT gate (inverter) is the simplest logic gate and is fundamental to the construction of all other gates. Understanding NOT is essential for working with complement arithmetic and signed number representations.

How are bitwise operations used in permission and flag systems?

Flag systems pack multiple boolean values into a single integer, using each bit as a separate on/off switch. Common examples include Unix file permissions (read=4, write=2, execute=1), window style flags in GUI programming, and feature flags in configuration systems. To check a flag: (value AND flag) != 0. To set a flag: value = value OR flag. To clear a flag: value = value AND (NOT flag). To toggle a flag: value = value XOR flag. This approach is memory-efficient (32 flags in one integer versus 32 separate booleans) and fast (all flag operations are single CPU instructions). Database systems often use bit flags for storing multiple boolean attributes in a single column, significantly reducing storage requirements.

References

Reviewed by Manoj Kumar, Mathematics Educator · Editorial policy