22 minutes ago · Tech · 0 comments

Today I learned something that is probably already well-known in some circles… but I hadn’t noticed it before and it made me go “wow”: There’s a really simple algorithm for converting ISO 3166-1 alpha-2 country codes into the emoji representations of the flags of those countries. I made an interactive to show how it works (enter a two-letter country code!). There’s a longer explanation below: Here’s the essence of the algorithm: Take the two-letter country code, e.g. FR for France. Get the character code of the uppercase variant of each letter: so F becomes 70 and R becomes 82.1 Add 127,397 to each of them, so now F is 127,467 and R 127,479. Render the unicode characters at those codepoints: F turns into 🇫 and R turns into 🇷. Concatenate those characters and you get the emoji of the flag: 🇫🇷 I’ve often find things that are wonderfully clever about Unicode, but this might be my new favourite. func countryEmojiFlag(countryCode string) string { cc :=…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.