Binary Arithmetic Calculator Formula

Understand the math behind the binary arithmetic calculator. Each variable explained with a worked example.

Formulas Used

Sum Val

sum_val = a + b

Diff Val

diff_val = a - b

And Val

and_val = bitAnd(a, b)

Or Val

or_val = bitOr(a, b)

Xor Val

xor_val = bitXor(a, b)

Variables

VariableDescriptionDefault
aNumber A42
bNumber B15

How It Works

Binary Arithmetic

Bitwise Operations

  • AND: both bits must be 1 → result is 1
  • OR: at least one bit must be 1 → result is 1
  • XOR: exactly one bit must be 1 → result is 1
  • Example: 42 AND 15

  • 42 in binary: 101010
  • 15 in binary: 001111
  • AND result: 001010 = 10
  • Bitwise operations work on individual bits of the binary representation.

    Worked Example

    Binary operations on 42 and 15.

    a = 42b = 15
    1. 0142 + 15 = 57
    2. 0242 - 15 = 27
    3. 0342 AND 15: 101010 AND 001111 = 001010 = 10
    4. 0442 OR 15: 101010 OR 001111 = 101111 = 47
    5. 0542 XOR 15: 101010 XOR 001111 = 100101 = 37

    Frequently Asked Questions

    What are bitwise operations?

    Bitwise operations work on individual bits of binary numbers. AND, OR, and XOR compare corresponding bits of two numbers.

    Where are bitwise operations used?

    In programming for flags/permissions, network subnet masks, graphics, encryption, and low-level hardware communication.

    What is XOR?

    XOR (exclusive or) returns 1 when the bits are different and 0 when they are the same. It is used in encryption and error detection.

    Ready to run the numbers?

    Open Binary Arithmetic Calculator