fork download
  1. object Main extends App {
  2. def toBits(byte: Byte): List[Int] = {
  3. (0 to 7).foldLeft(List[Int]())((list, i) => isBitSet(byte, i) :: list)
  4. }
  5.  
  6. private def isBitSet(byte: Byte, bit: Int) = ((byte >> bit) & 1)
  7.  
  8. val test = toBits(171.toByte);
  9. println(test)
  10. }
Success #stdin #stdout 0.36s 322240KB
stdin
Standard input is empty
stdout
List(1, 0, 1, 0, 1, 0, 1, 1)