Created
December 1, 2022 15:11
-
-
Save kddnewton/4be93efd5aafe0e614de9a2680a5b9c4 to your computer and use it in GitHub Desktop.
Emoji encoding
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
def c2e(string) = string.chars.map { |char| [char.ord + 128000].pack("U") }.join | |
def e2c(string) = string.unpack("U*").pack("c*") | |
c2e("Hello, world!") | |
# => "ππ₯π¬π¬π―π¬π π·π―π²π¬π€π‘" | |
e2c("ππ₯π¬π¬π―π¬π π·π―π²π¬π€π‘") | |
# => "Hello, world!" | |
e2c(c2e("Hello, world!")) | |
# => "Hello, world!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment