Shawn Karber_
04/27/2020, 3:24 PMfun convertHexToBitString(dataString: String) : String {
val binaryArray: MutableList<String> = arrayListOf()
dataString.toCharArray().forEach {
val binValue =
if (it.isDigit()) {
String.format("%4s",
Integer.toBinaryString(Character.getNumericValue(it)))
.replace(' ', '0')
} else {
when(it.toUpperCase()) {
'A' -> "1010"
'B' -> "1011"
'C' -> "1100"
'D' -> "1101"
'E' -> "1110"
'F' -> "1111"
else -> "Invalid hexadecimal digit in string."
}
}
binaryArray.add(binValue)
}
return binaryArray.joinToString("")
it.isDigit() is not working in common.kt, nor is Character.getNumericValue, and neither is String.format(). Are any of these accessible through another means in Kotlin Multiplatform?Sam
04/27/2020, 4:00 PMisDigit
is only available in Jvm and Native. See https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/is-digit.html. If you’re not targeting JS you can use expect/actual functions for jvm and native. If you need js support you’ll need to implement the function yourself on that platform.saket
04/27/2020, 4:13 PMString.format
is also available only on JVM.russhwolf
04/27/2020, 5:09 PMarrayListOf()
is jvm-only but you can use mutableListOf()
instead.