What does bitwise OR (|) do?

Prepare for the Computer Programming Test. Dive into a world of coding with multiple choice questions, flashcards, and detailed explanations. Boost your knowledge and be exam-ready!

Multiple Choice

What does bitwise OR (|) do?

Explanation:
Bitwise OR processes each bit individually, producing a 1 in each position where either input bit is 1. In other words, it combines the ones from both numbers: if either bit is 1, the result’s bit is 1; if both are 0, it’s 0. For example, 5 (0101) OR 3 (0011) gives 7 (0111). This operation has no carries or cross-position effects like addition, and it’s commonly used to turn on specific bits in a bitmask, such as result = flags | FLAG_A to ensure FLAG_A is set. It’s different from AND (which requires both bits to be 1), NOT (which flips bits), and shifting (which moves bits left or right).

Bitwise OR processes each bit individually, producing a 1 in each position where either input bit is 1. In other words, it combines the ones from both numbers: if either bit is 1, the result’s bit is 1; if both are 0, it’s 0. For example, 5 (0101) OR 3 (0011) gives 7 (0111). This operation has no carries or cross-position effects like addition, and it’s commonly used to turn on specific bits in a bitmask, such as result = flags | FLAG_A to ensure FLAG_A is set. It’s different from AND (which requires both bits to be 1), NOT (which flips bits), and shifting (which moves bits left or right).

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy