Bitwise Or Calculator

Written by:
PK

Use this bitwise OR calculator to compare bits and return 1 where either bit is 1. OR is commonly used for setting bits and combining flags.

Bitwise OR calculator

Using the calculator

Enter two numbers and select an input format for each: Decimal, Hex, Binary, or Octal. You can also type prefixes directly (0xFF for hex, 0b1010 for binary, or 0o17 for octal) and the tool will auto-detect the format.

The result displays in all formats simultaneously: decimal (signed and unsigned), hexadecimal, octal, and a 32-bit binary representation with spaces every 8 bits for readability.

How bitwise OR works

Bitwise OR (written as |) compares each bit of two numbers. It returns 1 if either bit is 1, and 0 only if both bits are 0. Think of it as "at least one must be true."

The OR truth table:

ABA | B
000
011
101
111

Bitwise OR example

Comparing the binary representations bit by bit:

00101100 (44)
00011000 (24)
────────
00111100 (60)

Any position with at least one 1 becomes 1 in the result. In other words: 44 | 24 = 60.

Common uses for OR

Set bits: OR with a mask to turn on specific bits. For example, flags | 0x04 sets bit 2 regardless of its previous state.

Combine flags: Multiple flags can be combined into one value: READ | WRITE | EXECUTE

Pack values: Combine separate values into a single integer. For 24-bit RGB colors: (red << 16) | (green << 8) | blue

Set bit unconditionally: x | (1 << n) sets bit n to 1 regardless of its current value.

      

PK

PK started DQYDJ in 2009 to research and discuss finance and investing and help answer financial questions. He's expanded DQYDJ to build visualizations, calculators, and interactive tools.

PK lives in New Hampshire with his wife, kids, and dog.

Don't Quit Your Day Job...

DQYDJ may be compensated by our partners if you make purchases through links. See our disclosures page. As an Amazon Associate we earn from qualifying purchases.
Sign Up For Emails
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram