Challenge - 5 Problems
Bitwise Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of bitwise AND operation
What is the output of the following Verilog code snippet?
Verilog
module test; reg [3:0] a = 4'b1101; reg [3:0] b = 4'b1011; wire [3:0] c; assign c = a & b; initial begin $display("%b", c); end endmodule
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 1101 and 1011 is 1001 because only the first and last bits are both 1.
❓ Predict Output
intermediateResult of bitwise OR operation
What will be printed by this Verilog code?
Verilog
module test; reg [3:0] x = 4'b0101; reg [3:0] y = 4'b0011; wire [3:0] z; assign z = x | y; initial begin $display("%b", z); end endmodule
Attempts:
2 left
💡 Hint
Bitwise OR returns 1 if at least one bit is 1.
✗ Incorrect
0101 OR 0011 results in 0111 because any bit that is 1 in either operand becomes 1.
❓ Predict Output
advancedOutput of bitwise XOR operation
What is the output of this Verilog code snippet?
Verilog
module test; reg [3:0] p = 4'b1100; reg [3:0] q = 4'b1010; wire [3:0] r; assign r = p ^ q; initial begin $display("%b", r); end endmodule
Attempts:
2 left
💡 Hint
Bitwise XOR returns 1 only if bits differ.
✗ Incorrect
1100 XOR 1010 equals 0110 because bits differ in positions 2 and 3.
❓ Predict Output
advancedResult of bitwise NOT operation
What will this Verilog code print?
Verilog
module test; reg [3:0] val = 4'b1010; wire [3:0] not_val; assign not_val = ~val; initial begin $display("%b", not_val); end endmodule
Attempts:
2 left
💡 Hint
Bitwise NOT flips each bit: 1 becomes 0, 0 becomes 1.
✗ Incorrect
The NOT of 1010 is 0101 because each bit is inverted.
🧠 Conceptual
expertUnderstanding combined bitwise operations
Given the following Verilog code, what is the output printed?
Verilog
module test; reg [3:0] a = 4'b1100; reg [3:0] b = 4'b1010; wire [3:0] result; assign result = ~(a & b) | (a ^ b); initial begin $display("%b", result); end endmodule
Attempts:
2 left
💡 Hint
Break down the expression step-by-step: AND, NOT, XOR, then OR.
✗ Incorrect
a & b = 1000; ~(a & b) = 0111; a ^ b = 0110; 0111 | 0110 = 0111.
