Skip to content

Instantly share code, notes, and snippets.

@ssaurel
Created July 6, 2018 08:40
Show Gist options
  • Save ssaurel/3dd9a3e247ed582242a45a9d646dcedb to your computer and use it in GitHub Desktop.
Save ssaurel/3dd9a3e247ed582242a45a9d646dcedb to your computer and use it in GitHub Desktop.
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