← ProblemsCircuits / Combinational Logic / Basic Gates

Gates and vectors

36%vectorsbasics

You 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 whether in[i] and its higher neighbour in[i+1] are both 1. Since in[3] has no higher neighbour, out_both only covers bits 2..0.
  • out_any[3:1] — bit i indicates whether in[i] or its lower neighbour in[i-1] is 1. Since in[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 whether in[i] is different from its higher neighbour. Here the vector wraps around, so the "higher neighbour" of in[3] is in[0].

Each output can be computed as a single bitwise operation between two part-selects (use concatenation for the wrap-around).