Bit manipulation in Scala