Skip to content

Instantly share code, notes, and snippets.

@invkrh
Created January 2, 2019 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save invkrh/fa911f8d31d3efbd3c54fe36225217f9 to your computer and use it in GitHub Desktop.
Save invkrh/fa911f8d31d3efbd3c54fe36225217f9 to your computer and use it in GitHub Desktop.
Function convert string to UTF-8 binary string
import java.nio.charset.StandardCharsets
def encode(s: String): Array[String] = {
StandardCharsets.UTF_8.encode(s).array.filter(_ != 0).map(b => "%08d".format((b & 0xFF).toBinaryString.toInt))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment