SystemVerilog #68 · 2026-11-30 · Ascending ranges · Easy · about 12 min
Reading a byte numbered from the left
bit_view receives a byte a from a link whose bits are numbered from the left: it is declared logic [0:7] a, so a[0] is its leftmost bit and a[7] its rightmost. The module hands that byte to logic that uses ordinary [7:0] and [3:0] vectors. It is purely combinational, with four outputs:
same(8 bits):same[i]isa[i]for everyifrom 0 to 7.flip(8 bits):flip[i]isa[7-i]for everyi.head(4 bits): the four leftmost bits ofa, witha[0]as the most significant bit ofhead(sohead[3]isa[0]andhead[0]isa[3]).tail(4 bits): the four rightmost bits ofa, witha[4]as the least significant bit oftail(sotail[0]isa[4]andtail[3]isa[7]).
Examples:
a (printed left to right) |
same |
flip |
head |
tail |
|---|---|---|---|---|
1111_1111 |
1111_1111 |
1111_1111 |
1111 |
1111 |
1001_1001 |
1001_1001 |
1001_1001 |
1001 |
1001 |
Fill in bit_view in bit_view.sv. Don't change the port declarations.
Write and run your answer in the browser. The hidden tests check it, and it’s free.