The easiest way to do this is to do a bit-wise and. So something like:
Code:generate i (gN-1,0)
V(gain_out[i]) <+ transition(gain_in & (1 << i) ? 1 : 0, 0, 1u) * (V(vdd) - V(vssr)) + V(vssr);
Use of the transition function is also important.
Use of genvars is now preferred over use of the generate statement, so you should probably use:
Code:genvar i;
for (i = 0; i < gN; i = i+1)
V(gain_out[i]) <+ transition(gain_in & (1 << i) ? 1 : 0, 0, 1u) * (V(vdd) - V(vssr)) + V(vssr);
-Ken