Bitwise OR (|): The bitwise OR operator (|) returns a 1 in each bit position for which the corresponding bits of either or both operands are 1s. Here, we will perform the bitwise OR operation between two variables and print the result.
The source code to demonstrate the bitwise OR (|) operator is given below. The given program is compiled and executed successfully.
// Rust program to demonstrate the
// bitwise OR (|) operator
fn main() {
let mut num1:i32 = 8;
let mut num2:i32 = 2;
let mut res:i32 = 0;
res = num1 | num2;
println!("{0} | {1} = {2}",num1,num2,res);
}
Output:
8 | 2 = 10
Explanation:
Here, we created three integer variables num1, num2, res that are initialized with 8, 2, 0 respectively. Then we performed the bitwise OR operation and printed the result.
Program/Source Code:
The source code to demonstrate the bitwise OR (|) operator is given below. The given program is compiled and executed successfully.
Output:
Explanation:
Here, we created three integer variables num1, num2, res that are initialized with 8, 2, 0 respectively. Then we performed the bitwise OR operation and printed the result.
Evolution of expression:
need an explanation for this answer? contact us directly to get an explanation for this answer