Skip to content

Online Binary Logic Calculator

    Use this binary logic calculator to compare two bit strings with AND, OR, XOR and NOR. See all four results together and use the explanations below to understand the rules, masks and flags behind them.

    Number systems

    Binary Logic Calculator

    Calculate AND, OR, XOR and NOR for two binary numbers. Every answer keeps the same number of bits as your inputs.

    Your binary numbers

    Enter 1–16 bits using only 0s and 1s.

    Use the same number of bits as A; add leading zeros if needed.

    AND

    —

    Enter your values to calculate.

    AND is 1 when both bits are 1. OR is 1 when at least one bit is 1. XOR is 1 when the bits differ.

    NOR reverses OR within the entered width. For example, NOR of 00 and 00 is 11.

    Logic truth table
    The result of each operation for one pair of bits.
    ABANDORXORNANDNORXNORNOT(A)
    000001111
    010111001
    100111000
    111100010

    For binary logic on your phone, Unit Converter is free to download and includes a Binary Logic tool.

    How to use this tool

    1. Enter Binary A using only zeros and ones, with a length of 1–16 bits.
    2. Enter Binary B with the same number of bits. Retain or add leading zeros to match the widths.
    3. Click Calculate to see AND, OR, XOR and NOR at the entered width.

    What is binary logic?

    Binary logic works with values that have two possible states, written as 0 and 1. Each digit is a bit. A group of bits can represent a number or a collection of independent on/off settings, depending on how the data is used.

    A binary logic calculator applies a logical rule to each pair of matching positions in two bit strings. It shows which positions satisfy that rule, making it useful for studying digital logic, checking masks and comparing binary data.

    How AND, OR, XOR and NOR work

    Each operation examines one bit from A and the bit in the same position in B. A result bit of 1 means that the operation’s condition is met:

    AND
    Produces 1 only when both input bits are 1. All other pairs produce 0.
    OR
    Produces 1 when at least one input bit is 1. This includes the case where both bits are 1.
    XOR, or exclusive OR
    Produces 1 when the two input bits differ. Matching bits produce 0.
    NOR, or NOT OR
    Reverses the OR result at each position. It produces 1 only when both input bits are 0.

    AND and OR therefore test different conditions: both inputs versus at least one input. XOR identifies differences, while NOR identifies positions where neither input has a set bit. Microsoft’s bitwise-operator reference explains the corresponding AND, OR and XOR rules.

    Working one position at a time

    These bitwise operations repeat the same rule independently across the whole input. There is no carry from one position to the next as there can be in addition. The position of a bit matters because it lines up with the corresponding position in the other input.

    A truth table lists the possible pairs of input states and the result for each operation. The tool’s expandable truth table provides this reference for individual bits; the calculated results apply those rules across the full strings.

    Bit masks and flags

    A flag uses a bit to record whether a setting or condition is active. Assigning different flags to different positions lets one value hold several settings. A mask is a bit pattern that selects the positions an operation should affect.

    • AND with a mask keeps the original bits wherever the mask contains 1 and clears the other positions.
    • OR with a mask sets the selected positions to 1 while leaving the others unchanged.
    • XOR with a mask flips the selected positions and preserves the others.

    These relationships make it possible to check, combine or change flags without rebuilding every setting individually. Comparing two stored patterns with XOR also marks the positions that changed. MDN explains how flags share a single value.

    Why bit width and leading zeros matter

    The bit width is the number of positions in a bit string. Leading zeros keep those positions visible, which helps preserve a register, field or mask layout. This calculator keeps every result at the same width as its inputs.

    Width is especially important for NOR. After combining the inputs with OR, the calculator flips only the bits within the entered width. The result is a finite bit pattern with no extra positions added at the left. Interpreting that pattern as a signed or unsigned number is a separate step; the logical rules operate on the bits themselves.

    More tools: Browse all calculators and unit converters.

    Work with binary logic on your phone

    Use the Binary Logic tool and other number tools in Unit Converter wherever you need them. Download it free from the App Store or Google Play.

    Leave a Reply

    Your email address will not be published. Required fields are marked *