Challenge - 5 Problems
Master of Reduction Operators
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of reduction AND operator
What is the output of the following Verilog code snippet?
module test;
reg [3:0] a = 4'b1101;
wire out;
assign out = &a;
initial begin
$display("out = %b", out);
end
endmoduleVerilog
module test; reg [3:0] a = 4'b1101; wire out; assign out = &a; initial begin $display("out = %b", out); end endmodule
Attempts:
2 left
💡 Hint
The reduction AND operator returns 1 only if all bits are 1.
✗ Incorrect
The input 'a' is 1101. Since not all bits are 1 (the second bit is 0), the reduction AND (&a) outputs 0.
❓ Predict Output
intermediateOutput of reduction OR operator
What will be printed by this Verilog code?
module test;
reg [3:0] b = 4'b0000;
wire out;
assign out = |b;
initial begin
$display("out = %b", out);
end
endmoduleVerilog
module test; reg [3:0] b = 4'b0000; wire out; assign out = |b; initial begin $display("out = %b", out); end endmodule
Attempts:
2 left
💡 Hint
The reduction OR operator returns 1 if any bit is 1.
✗ Incorrect
Since all bits in b are 0, the reduction OR (|b) outputs 0.
❓ Predict Output
advancedOutput of reduction XOR operator
What is the output of this Verilog code?
module test;
reg [3:0] c = 4'b1011;
wire out;
assign out = ^c;
initial begin
$display("out = %b", out);
end
endmoduleVerilog
module test; reg [3:0] c = 4'b1011; wire out; assign out = ^c; initial begin $display("out = %b", out); end endmodule
Attempts:
2 left
💡 Hint
The reduction XOR operator returns 1 if the number of 1 bits is odd.
✗ Incorrect
The bits in c are 1,0,1,1 which has three 1s (odd count), so ^c outputs 1.
❓ Predict Output
advancedValue of variable after reduction NAND operator
What value does 'out' hold after this code runs?
module test;
reg [3:0] d = 4'b1111;
wire out;
assign out = ~&d;
initial begin
$display("out = %b", out);
end
endmoduleVerilog
module test; reg [3:0] d = 4'b1111; wire out; assign out = ~&d; initial begin $display("out = %b", out); end endmodule
Attempts:
2 left
💡 Hint
NAND is the negation of AND.
✗ Incorrect
Since &d is 1 (all bits 1), ~&d is 0.
🧠 Conceptual
expertUnderstanding reduction NOR operator behavior
Given the Verilog code below, what is the output?
module test;
reg [3:0] e = 4'b0001;
wire out;
assign out = ~|e;
initial begin
$display("out = %b", out);
end
endmoduleVerilog
module test; reg [3:0] e = 4'b0001; wire out; assign out = ~|e; initial begin $display("out = %b", out); end endmodule
Attempts:
2 left
💡 Hint
Reduction NOR is the negation of reduction OR.
✗ Incorrect
Since |e is 1 (because one bit is 1), ~|e is 0.
