I had a similar one shot need, here is a strait forward logic hack to do the trick -- some one write a script to expand for any number bits, I wrote it out for 16 -- example for 4.
You pick what you want in case all bits are zero, I put -1 as a template.
Plus it takes a start bit position to start looking from.
case (start_bit)
0: bit = x[0] ? 0 : x[1] ? 1: x[2] ? 2: x[3] ? 3: -1;
1: bit = x[1] ? 1: x[2] ? 2: x[3] ? 3 : -1;
2: bit = x[2] ? 2: x[3] ? 3 : -1;
3: bit = x[3] ? 3 : -1;
endcase