What will be the final value printed for result ? reg signed [3:0] val; r…
What will be the final value printed for result ? reg signed [3:0] val; reg [7:0] result; initial begin val = -4'sd3; // 4-bit two's complement of 3 result = {{2{val[3]}}, val, 2'b00}; $display("%b", result); end
- 11110100
- 11110101
- 00110100
- 11110000
Correct answer
A. 11110100
Explanation
1. The 4-bit two's complement representation of $+3$ ( 4'b0011 ) inverted and plus 1 gives $-3$: 4'b1101 . 2. val[3] is 1'b1 . 3. {2{val[3]}} replicates the sign bit twice: 2'b11 . 4. Concatenating {2'b11, 4'b1101, 2'b00} forms the 8-bit vector 8'b11110100 .