use Bit::Manip qw(:all); use Test::More; # out of order sequence my @exp0123 = (0..15); my @exp3210 = reverse(0..15); my @exp0312 = (0b0000,0b0001,0b0100,0b0101,0b1000,0b1001,0b1100,0b1101,0b0010,0b0011,0b0110,0b0111,0b1010,0b1011,0b1110,0b1111); for (0 .. 15) { is( bit_set(0x00, 2, 4, $_), $_ << 2, "nomal set, shifted up 2" ); is( bit_set_seq(0x00, [0,1,2,3], $_), $exp0123[$_], "[0,1,2,3]: I expect bit 0 [LSB] of input to be transferred to bit 0 [LSB] of output -- ie, same order"); is( bit_set_seq(0x00, [3,2,1,0], $_), $exp3210[$_], "[3,2,1,0]: I expect bit 3 [MSB] of input to be transferred to bit 0 [LSB] of output, in2 -> out1, in1 -> out2, in0 -> out3 -- ie, reverse the bits"); is( bit_set_seq(0x00, [0,3,1,2], $_), $exp0312[$_], "[0,3,1,2]: I expect in0 -> out0, in3->out1, in1->out2, in2->out3"); } ... # your subs go below, not quoted here...