Design and verify a module which finds the second bit set from LSB for a N-bit vector.
- Output should be produced in a single cycle
- Output must be one-hot or zero
The module should have the following interface:
module Second_Bit_Set_from_LSB #(
parameter WIDTH = 12
)(
input wire [WIDTH-1:0] vec_i,
output wire [WIDTH-1:0] second_bit_o
);This module is designed to find the first and second set bits in a given vector vec_i. The first set bit is the lowest 1 bit encountered when moving from right to left. The second set bit is found after clearing the first set bit.
The module performs the following steps:
- Find the first set bit in
vec_i. - Clear the first set bit from
vec_i. - Find the second set bit in the modified vector.
Example: vec_i = 12'b001001000000
Let’s walk through an example where vec_i = 12'b001001000000 (in binary).
first_bit_mask = 12'b001001000000 & 12'b110111000000
= 12'b000001000000cleared_vec = 12'b001001000000 & 12'b111110111111
= 12'b001000000000second_bit_o = 12'b001000000000 & 12'b110111111111
= 12'b000000100000In this example:
- The first set bit is at position 4 (counting from 0).
- The second set bit is at position 7.