How this calculator works
A bitwise operation compares the two numbers one bit position at a time. AND keeps a 1 only where both inputs have a 1, which is how a mask selects bits. OR sets a 1 where either input has one. XOR sets a 1 where the inputs differ, so it toggles chosen bits and is also used to detect parity. NOR, XNOR and NAND invert the corresponding basic result. Results are masked to the chosen width, then shown in binary, octal and decimal. The signed decimal value reads the leading bit as a negative place value; for example, 10011001 in 8 bits reads as 153 unsigned and -103 signed.
Formula
For every bit position i: AND is aᵢ · bᵢ, OR is aᵢ + bᵢ - aᵢbᵢ, and XOR is aᵢ + bᵢ mod 2. NOR is NOT(OR), XNOR is NOT(XOR), and NAND is NOT(AND). The stored result is then reduced modulo 2ⁿ, where n is the bit width.
Worked example
In 8 bits, 11001100 AND 10101010 is 10001000 (204 AND 170 = 136). OR gives 11101110 (238), XOR gives 01100110 (102), and NOR gives 00010001 (17). Reading 10001000 as a signed 8-bit number still gives 136 because its leading bit is 0, while 10011001 has a leading 1 and reads as -103.
Advertisement
Frequently asked questions
What is the difference between XOR and OR?
OR sets a bit when either input is 1, including when both are 1. XOR sets a bit only when the inputs differ, so it is 0 when both are 1. That makes XOR useful for toggling bits and for parity checks.
Why are the results shown in octal as well as binary?
Octal groups binary digits in threes, so it is a compact way to read a bit pattern. Each octal digit maps directly to three binary bits, which is why 11101110 groups as 11 101 110 and reads as 356.
What does NOR mean?
NOR is an OR result with every bit flipped inside the chosen width. Wherever OR gives 1, NOR gives 0, and wherever OR gives 0, NOR gives 1. It is called a universal gate because AND, OR and NOT can all be built from it.
Why is the signed decimal different from the unsigned one?
They read the same bit pattern differently. Unsigned decimal treats the leading bit as an ordinary positive place value. Signed decimal uses two's complement, where the leading bit contributes a negative value, which is the standard reading inside a computer.