Challenge - 5 Problems
Bitwise Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2: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);
}Attempts:
2 left
๐ก Hint
Bitwise AND compares each bit of two numbers and returns 1 only if both bits are 1.
โ Incorrect
The bitwise AND of 0b11001010 and 0b10101100 results in 0b10001000 because only bits in positions 7 and 3 are both 1.
โ Predict Output
intermediate2: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);
}Attempts:
2 left
๐ก Hint
Bitwise OR returns 1 if either bit is 1.
โ Incorrect
The OR of 0b01010101 and 0b00111100 is 0b01111101 because any bit set in either number becomes 1.
โ Predict Output
advanced2: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);
}Attempts:
2 left
๐ก Hint
Bitwise XOR returns 1 only if bits differ.
โ Incorrect
XOR of 0b11110000 and 0b10101010 is 0b01011010 because bits differ in positions 6,4,3,1.
โ Predict Output
advanced2: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);
}Attempts:
2 left
๐ก Hint
Left shift moves bits to the left, adding zeros on the right.
โ Incorrect
Shifting 0b00011110 left by 3 moves bits three places left, resulting in 0b11100000.
โ Predict Output
expert3: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);
}Attempts:
2 left
๐ก Hint
Bitwise NOT flips all bits; then AND with b keeps only bits set in both.
โ Incorrect
NOT of 0b10101010 is 0b01010101; AND with 0b11001100 results in 0b01000100.