Hello guys, I found a logic mistake in the source code that is been given with the book.

Given a number as a double value and determine if this number is a power of 2 by using a loop instead

o log2() function. It goes as follows.

val number = 1024.0 //The number you want to check if is a power of 2

var dividend = number

while ("%.0f".format(dividend % 2).toInt() == 0) {

dividend /= 2

}

if (dividend == 1.0) {

println("$number is a power of 2")

} else {

println("$number is not a power of 2")

}

Of course, you can make it using other loops as well. That one, it works fine!