blob: 1ac70725f3c0b8795428a54ecb2755db6da29069 [file] [log] [blame]
package utils
object MathUtils {
def intLog2(x: Int): Int = {
val log = (Math.log(x) / Math.log(2.0)).round.toInt
assert((1 << log) == x)
return log
}
implicit class BinStrToInt(val sc: StringContext) extends AnyVal {
def b(args: Any*): Int = {
val strings = sc.parts.iterator
val expressions = args.iterator
val buf = new StringBuilder(strings.next())
while(strings.hasNext) {
buf.append(expressions.next())
buf.append(strings.next())
}
Integer.parseInt("0" + buf.toString
.replaceAll("_", "")
.replaceAll(" ", ""), 2)
}
}
}