Created
January 2, 2019 15:33
-
-
Save invkrh/fa911f8d31d3efbd3c54fe36225217f9 to your computer and use it in GitHub Desktop.
Function convert string to UTF-8 binary string
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
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