Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Binary Converter Kotlin object for the Binary Converter App on the SSaurel's Channel
package com.ssaurel.binaryconverter
object BinaryConverter {
// convert text to binary
fun strToBinary(str:String) : String {
val builder = StringBuilder()
for (c in str.toCharArray()) {
val toString = Integer.toString(c.toInt(), 2); // get char value in binary
builder.append(String.format("%08d", Integer.parseInt(toString))); // we complete to have 8 digits
}
return builder.toString()
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment