← ProblemsCircuits / Combinational Logic / Basic Gates
Gates and vectors
36%vectorsbasicsYou are given a 4-bit input in[3:0]. Think of its bits as four items in a row; produce three outputs that relate each bit to its neighbours:
out_both[2:0]— bit i indicates whetherin[i]and its higher neighbourin[i+1]are both 1. Sincein[3]has no higher neighbour,out_bothonly covers bits 2..0.out_any[3:1]— bit i indicates whetherin[i]or its lower neighbourin[i-1]is 1. Sincein[0]has no lower neighbour, this output is declared with range[3:1](a 3-bit vector whose lowest bit is bit 1).out_different[3:0]— bit i indicates whetherin[i]is different from its higher neighbour. Here the vector wraps around, so the "higher neighbour" ofin[3]isin[0].
Each output can be computed as a single bitwise operation between two part-selects (use concatenation for the wrap-around).