Challenge - 5 Problems
Bit Vector Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateUnderstanding bit vector width and indexing
What is the value of
out after this Verilog code runs?module test; reg [3:0] in = 4'b1011; wire out; assign out = in[2]; endmodule
Verilog
module test; reg [3:0] in = 4'b1011; wire out; assign out = in[2]; endmodule
Attempts:
2 left
💡 Hint
Remember that bit indexing starts at 0 from the rightmost bit.
✗ Incorrect
The vector
in is 4 bits: bits 3 to 0. The bits are 1(3),0(2),1(1),1(0). So in[2] is 0.❓ Predict Output
intermediateBus declaration and concatenation output
What is the 8-bit value of
bus_out after this code?module test;
wire [3:0] a = 4'b1100;
wire [3:0] b = 4'b0011;
wire [7:0] bus_out;
assign bus_out = {a, b};
endmoduleVerilog
module test; wire [3:0] a = 4'b1100; wire [3:0] b = 4'b0011; wire [7:0] bus_out; assign bus_out = {a, b}; endmodule
Attempts:
2 left
💡 Hint
Concatenation puts the first vector on the left (higher bits).
✗ Incorrect
Concatenation {a, b} places
a in bits 7:4 and b in bits 3:0, so bus_out = 1100 0011.❓ Predict Output
advancedEffect of reversed bit vector declaration
What is the value of
out after this code?module test; reg [0:3] in = 4'b1011; wire out; assign out = in[0]; endmodule
Verilog
module test; reg [0:3] in = 4'b1011; wire out; assign out = in[0]; endmodule
Attempts:
2 left
💡 Hint
Bit vector ranges can be declared with the left index smaller than the right index.
✗ Incorrect
The vector
in is declared from 0 to 3, so in[0] is the leftmost bit of 4'b1011 which is 1.❓ Predict Output
advancedBus slicing and output value
What is the 3-bit value of
slice after this code?module test; wire [7:0] bus = 8'b10110110; wire [2:0] slice; assign slice = bus[5:3]; endmodule
Verilog
module test; wire [7:0] bus = 8'b10110110; wire [2:0] slice; assign slice = bus[5:3]; endmodule
Attempts:
2 left
💡 Hint
Remember bit 7 is leftmost, bit 0 is rightmost.
✗ Incorrect
bus = 10110110, bits 5 to 3 are bits 5=1,4=1,3=0, so slice = 3'b110.
🧠 Conceptual
expertBus declaration and default values in Verilog
Which statement about Verilog bit vector declarations is TRUE?
Attempts:
2 left
💡 Hint
Think about default initialization of reg and wire types in Verilog.
✗ Incorrect
In Verilog,
reg variables keep their value until assigned, but are not automatically zeroed. wire without assignment is unknown (X). Declaring reg [0:7] is valid. Assigning 8'bZZZZZZZZ sets bits to high impedance (Z), not 1.