What is the result of the following operation? System.out.println(4 | 3);
-
6
-
0
-
1
-
7
Bitwise OR (|) combines binary representations. 4 is 100, 3 is 011. OR yields 111 (binary) = 7 (decimal). Each bit is 1 if either operand has a 1 in that position.
To determine the result of the given operation System.out.println(4 | 3);, we need to understand the bitwise OR operator (|) in Java.
The bitwise OR operator (|) performs a bitwise OR operation on each pair of corresponding bits in the operands. It returns 1 if either of the corresponding bits is 1, and 0 otherwise.
In this case, the operands are 4 and 3. Let's convert these numbers to binary representation:
4 in binary: 100 3 in binary: 011
Performing the bitwise OR operation on each pair of corresponding bits, we get:
100 | 011
111
The result of the operation is 111, which is equivalent to the decimal number 7.
Therefore, the correct answer is D) 7.