Complete the code to perform a bitwise AND between two numbers.
let result = 5 [1] 3; println!("{}", result);
The bitwise AND operator is &. It compares each bit of two numbers and returns 1 only if both bits are 1.
Complete the code to perform a bitwise OR between two numbers.
let result = 5 [1] 3; println!("{}", result);
The bitwise OR operator is |. It compares each bit of two numbers and returns 1 if at least one bit is 1.
Fix the error in the code to perform a bitwise XOR between two numbers.
let result = 5 [1] 3; println!("{}", result);
The bitwise XOR operator is ^. It returns 1 only if the bits are different.
Fill both blanks to create a dictionary comprehension that maps numbers to their bitwise left shift by 2, only for numbers greater than 2.
let shifted = std::collections::HashMap::from_iter((1..6).filter(|&x| x [1] 2).map(|x| (x, x [2] 2))); println!("{:?}", shifted);
The filter should keep numbers greater than 2, so use >. The bitwise left shift operator is <<.
Fill all three blanks to create a HashMap that maps the bitwise NOT of numbers to their bitwise AND with 3, only for numbers less than 5.
let result = std::collections::HashMap::from_iter((0..10).filter(|&x| x [1] 5).map(|x| (!x, x [2] [3]))); println!("{:?}", result);
Filter numbers less than 5 using <. Use bitwise AND & with 3.