would kind of prefer a tailrec here like:
```scala
@annotation.tailrec
def loop(pos: Int, accum: Int): Int = {
  if(pos >= bits) accum
  else if (bsw.contains(pos)) loop(pos + 1, accum + (1 << pos))
  else loop(pos + 1, accum)
}
loop(0, 0)
```
tail rec is just as fast as a while loop (compiled to the same thing), but due to lack of mutable variables, is easier to see it is correct (in my view).