What is the 4-bit output printed by $display("%b", out) ? reg [3:0] in; r…
What is the 4-bit output printed by $display("%b", out) ? reg [3:0] in; reg [3:0] out; initial begin in = 4'b1101; out = {&in, |in, ^in, ~^in}; $display("%b", out); end
- 0110
- 0101
- 0111
- 1110
Correct answer
A. 0110
Explanation
* & in (Reduction AND): $1 \ \& \ 1 \ \& \ 0 \ \& \ 1 = 0$ * | in (Reduction OR): $1 \ \vert{} \ 1 \ \vert{} \ 0 \ \vert{} \ 1 = 1$ * ^ in (Reduction XOR): $1 \oplus 1 \oplus 0 \oplus 1 = 1$ * ~^ in (Reduction XNOR): $\sim(1 \oplus 1 \oplus 0 \oplus 1) = 0$ Concatenating {0, 1, 1, 0} results in 4'b0110 .