OR Gate Calculator

OR a set of values and watch every bit column resolve. Mix binary, decimal, hex, and octal operands, pick a register width from 8 to 64 bits, and read which operand turned each bit on.

Operands

Load an example

Bit grid

Every column is one bit position. A column turns on when at least one operand holds a 1 in it.

One gate, two inputs

Flip the inputs to see the gate settle. The matching row in the truth table lights up with it.

A
B
A + B0

Truth table

ABA OR BReads as
000Neither input is on
011B alone is enough
101A alone is enough
111Both on, still 1, not 2

That last row is the whole difference between OR and XOR. XOR drops back to 0 when both inputs are 1.

OR answers one question per bit column: is there a 1 anywhere in this column? Feed it 1010 and 0110 and you get 1110, because three of the four columns hold at least one 1. Nothing carries, nothing borrows, and column 3 never hears about column 2. That independence is why OR finishes in a single clock cycle on every processor built since the 1970s, and why it is the operator you reach for when you want to switch bits on and leave the rest of a value alone.

Reading the bit grid

The grid stacks your operands one per row, right aligned so bit 0 sits in the last column. The result row underneath is the OR of everything above it. Columns are grouped in fours, matching the way a hex digit maps to four bits, so you read 1111 0000 as F0 without counting on your fingers.

Set bits carry a colour. Hover or tap any column and the label names the bit position, its decimal weight, and which operands put a 1 there. That last detail matters when a mask is not doing what you expected: a bit already set in the base value looks identical to a bit the mask just switched on, until you check which row it came from.

Width is not decoration

The width selector masks every operand before the operation runs. At 8 bits, an input of 300 becomes 44, since 300 wraps to 0010 1100 once the ninth bit is discarded. The grid flags an operand when this happens instead of silently truncating it. Pick the width your target register uses, because a mask written for a 16 bit field behaves differently once it lands in an 8 bit one.

At 64 bits the arithmetic runs on BigInt, so the high bits stay exact. Values are treated as unsigned. If you are working with negative numbers in two's complement, convert first with the number base converter and paste the unsigned pattern in.

OR sets bits. It never clears one.

This is the property that gives OR its job. Once a bit reads 1, no operand you OR in afterwards returns it to 0. The operation only ever adds. That makes it safe for combining independent settings and useless for switching something off, which is what AND with an inverted mask handles.

READ = 0b0000_0100 // 4WRITE = 0b0000_0010 // 2EXECUTE = 0b0000_0001 // 1perms = READ | WRITE // 0b0000_0110, decimal 6perms = perms | EXECUTE // 0b0000_0111, decimal 7perms = perms | READ // still 7, the bit was already on

That final line is the point. OR is idempotent, so applying the same flag twice costs nothing and changes nothing. Code that rebuilds a permission set on every request stays correct without tracking what it already applied.

Unix file modes work this way, three bits per group and three groups per file. Mode 0644 is owner read plus write, group read, other read. OR it with 0111 and every group gains execute, giving 0755. Load the permission preset above and the grid draws the three groups side by side.

Logical OR and bitwise OR are different operators

The two get mixed up constantly, and the bug that follows is a quiet one. Bitwise OR works column by column on integers. Logical OR works on truth, returns one answer, and in most languages skips evaluating its right side once the left side is true.

LanguageBitwise ORLogical ORCatch worth knowing
C, C++, Java, C#|||Java and C# also allow | on booleans, which evaluates both sides
JavaScript|||| truncates to 32 bit signed, so large numbers change value
Python|orIntegers are arbitrary precision, so nothing wraps
PHP||| and oror binds looser than =, which surprises people at assignment
SQL| in T-SQL, a bit type elsewhereORThree valued logic: NULL OR TRUE is TRUE, NULL OR FALSE is NULL
Rust, Go|||No implicit conversion between integers and booleans

The JavaScript row bites hardest. Writing flags | 0 on a value above 2147483647 wraps it into negative territory, so bit masks wider than 31 bits belong in BigInt. This calculator uses BigInt at every width, which is why a 64 bit OR here matches what C prints and not what a browser console prints.

Where OR earns its place

Where this tool stops

It handles unsigned integers up to 64 bits and nothing else. Floating point values, negative decimal input, and text are rejected rather than coerced, since guessing at intent produces answers you cannot trust. Two's complement negatives need converting to their unsigned pattern first. There is no expression parser, so a mixed line like (a | b) & ~c has to be worked through one step at a time, and the bitwise calculator covers the other operators. Truth tables here stay at two inputs, since a chained OR across six operands reduces to the same two input rule applied five times.

Chaining more than two operands

OR is associative and commutative. (A | B) | C equals A | (B | C), and the order you list operands in never changes the result. The calculator accepts up to six for that reason, and the grid shows all of them at once instead of making you fold two at a time.

One consequence worth holding on to: a chained OR loses information. Given a result of 1111 you cannot work backwards to the inputs, because dozens of combinations produce it. If you need reversibility, XOR is the operator that gives it to you, since XORing the same value twice returns the original.

The gate behind the operator

A two input OR gate outputs high when either input is high. In CMOS it is built as a NOR gate followed by an inverter, six transistors in total, which is why NOR is often the cheaper primitive in hardware even though OR is the one people write in code.

De Morgan's law connects OR to AND directly: A + B = (A' · B')'. Invert both inputs, AND them, then invert the result, and you have an OR. NAND and NOR are each functionally complete on their own, so any circuit, including this OR, is buildable from copies of a single gate type. That property is what makes gate arrays practical to manufacture.

Boolean algebra writes OR as addition, so A + B. The identities follow straight from the truth table: A + 0 = A, A + 1 = 1, A + A = A, and A + A' = 1. The second one is the absorbing element, and it explains why ORing with an all ones mask hands back all ones no matter what you started with.

OR gate and bitwise OR questions

Operator differences, width behaviour, masking, and the cases that trip people up.

What is the difference between OR and XOR?

Only the last row of the truth table. Both return 1 when exactly one input is 1. When both inputs are 1, OR stays at 1 and XOR drops to 0. That makes OR a union of set bits and XOR a difference detector, which is why XOR is used for toggling and checksums while OR is used for combining flags.

Why does 5 OR 3 give 7 instead of 8?

OR is not addition. 5 is 101 and 3 is 011, and the OR takes each column separately: 1, 1, 1, giving 111 which is 7. Addition would carry the overlapping bit in column 0 into column 1 and reach 8. OR never carries, so the result is always less than or equal to the sum.

How do I set a single bit without touching the others?

OR the value with 1 shifted left by the bit position. To set bit 5 of a byte, OR it with 32, which is 0010 0000. Every other column keeps whatever it held, since ORing a bit with 0 returns that bit unchanged.

Can OR clear a bit?

No. Once a bit reads 1, no OR operation returns it to 0. Clearing a bit takes AND with a mask that holds 0 in that position and 1 everywhere else, usually written as AND NOT the mask. Toggling takes XOR.

What does the width setting change?

It masks each operand to that many bits before the operation. At 8 bits an input of 300 becomes 44, because the ninth bit is discarded. The grid marks any operand it had to truncate, so a wrap never happens without you seeing it. Set the width to match the register or field you are targeting.

Does this calculator handle negative numbers?

Not directly. Values are treated as unsigned, and a negative decimal is rejected instead of being converted. Two's complement representation depends on the width you intend, so converting first keeps the answer unambiguous. Once you have the unsigned bit pattern, paste it in as binary or hex.

Why is 0644 OR 0111 equal to 0755?

Those are octal file modes, three bits per digit. 0644 is owner read plus write, group read, other read. 0111 is the execute bit for all three groups. ORing them turns execute on everywhere while leaving the read and write bits as they were, which gives 0755, the usual mode for a directory or a script.

Is the pipe character in SQL a bitwise OR?

Depends on the engine. In T-SQL a single pipe is a bitwise OR on integer columns while the keyword OR is the logical one. PostgreSQL reads a double pipe as string concatenation, so bitwise work there needs the bit type or an explicit function. Check your dialect first, because both forms parse without error and return different results.

How many transistors does an OR gate use?

Six in standard CMOS, built as a NOR gate of four transistors followed by a two transistor inverter. NOR and NAND cost four transistors each, which is why hardware designers often restructure logic in terms of those two rather than using OR and AND directly.

Copied