0
0
Rustprogramming~20 mins

Bitwise operators in Rust - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Bitwise Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2:00remaining
What is the output of this bitwise AND operation?
Consider the following Rust code snippet. What will it print?
Rust
fn main() {
    let a: u8 = 0b1100_1010;
    let b: u8 = 0b1010_1100;
    println!("{:08b}", a & b);
}
A10000000
B10001000
C00000000
D11111111
Attempts:
2 left
๐Ÿ’ก Hint
Bitwise AND compares each bit of two numbers and returns 1 only if both bits are 1.
โ“ Predict Output
intermediate
2:00remaining
What is the output of this bitwise OR operation?
Look at this Rust code. What will it print?
Rust
fn main() {
    let x: u8 = 0b0101_0101;
    let y: u8 = 0b0011_1100;
    println!("{:08b}", x | y);
}
A00111100
B01111001
C01111101
D01010101
Attempts:
2 left
๐Ÿ’ก Hint
Bitwise OR returns 1 if either bit is 1.
โ“ Predict Output
advanced
2:00remaining
What is the output of this bitwise XOR operation?
Analyze this Rust code and determine the output.
Rust
fn main() {
    let p: u8 = 0b11110000;
    let q: u8 = 0b10101010;
    println!("{:08b}", p ^ q);
}
A00000000
B01010010
C11111010
D01011010
Attempts:
2 left
๐Ÿ’ก Hint
Bitwise XOR returns 1 only if bits differ.
โ“ Predict Output
advanced
2:00remaining
What is the output after left shifting?
What will this Rust program print?
Rust
fn main() {
    let num: u8 = 0b0001_1110;
    let shifted = num << 3;
    println!("{:08b}", shifted);
}
A11110000
B00011110
C11100000
D00000000
Attempts:
2 left
๐Ÿ’ก Hint
Left shift moves bits to the left, adding zeros on the right.
โ“ Predict Output
expert
3:00remaining
What is the output after combining bitwise NOT and AND?
Examine this Rust code and find the output.
Rust
fn main() {
    let a: u8 = 0b1010_1010;
    let b: u8 = 0b1100_1100;
    let result = (!a) & b;
    println!("{:08b}", result);
}
A01000100
B00110011
C01010101
D10101010
Attempts:
2 left
๐Ÿ’ก Hint
Bitwise NOT flips all bits; then AND with b keeps only bits set in both.