It's important to understand that the convention for hardware bit numbering is that bit 0 is the least significant bit. If the 3-bit sel bus is carrying the number 4, then sel[2]=1, sel[1]=0, and sel[0]=0.
This makes the relationship between bit number (n) and bit value (v) easy to remember: v=2n.
In the early days of computing different manufacturers used different schemes, some 1-based, some left-to-right, and as you can imagine, it was rather confusing.
--Mark
[It is OK to post snippets of code, just don't post entire solutions.]