Building a Bitmask in a Loop