Created
July 6, 2018 08:40
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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