Bit Manipulation

Kotlin 1.3.50

@UseExperimental(ExperimentalStdlibApi::class)
fun main() { 
  val number = "1010000".toInt(radix = 2)
  println(number.countOneBits())
  println(number.countTrailingZeroBits())
  println(number.takeHighestOneBit().toString(2))
  println(number.rotateRight(3).toString(2))
  println(number.rotateLeft(3).toString(2))
}

Back Home Next