As described in UTF-8 and in Wikipedia, UTF-8 is a popular encoding of (multi-byte) Unicode code-points into eight-bit octets.

The goal of this task is to write a encoder that takes a unicode code-point (an integer representing a unicode character) and returns a sequence of 1-4 bytes representing that character in the UTF-8 encoding.

Then you have to write the corresponding decoder that takes a sequence of 1-4 UTF-8 encoded bytes and return the corresponding unicode character.

Demonstrate the functionality of your encoder and decoder on the following five characters:

Character   Name                                  Unicode    UTF-8 encoding (hex)
---------------------------------------------------------------------------------
A           LATIN CAPITAL LETTER A                U+0041     41
ö           LATIN SMALL LETTER O WITH DIAERESIS   U+00F6     C3 B6
Ж           CYRILLIC CAPITAL LETTER ZHE           U+0416     D0 96
€           EURO SIGN                             U+20AC     E2 82 AC
𝄞           MUSICAL SYMBOL G CLEF                 U+1D11E    F0 9D 84 9E

Provided below is a reference implementation in Common Lisp.

import java.nio.charset.StandardCharsets;
 
Integer[] code_points = {0x0041, 0x00F6, 0x0416, 0x20AC, 0x1D11E};
 
void setup() {
  size(850, 230);
  background(255);
  fill(0);
  textSize(16);
  int tel_1 = 80;
  int tel_2 = 50;
  text("Char     Name                                                            Unicode          UTF-8 (encoding)      Decoded", 40, 40);
  for (int cp : code_points) {  
    byte[] encoded = new String(new int[]{cp}, 0, 1).getBytes(StandardCharsets.UTF_8);
    for (byte b : encoded) {                                                    
      text(hex(b), tel_2+530, tel_1);
      tel_2 += 30;
    }
    text(char(cp), 50, tel_1);
    text(Character.getName(cp), 100, tel_1);
    String unicode = hex(cp);
    while (unicode.length() > 4 && unicode.indexOf("0") == 0) unicode = unicode.substring(1);
    text("U+"+unicode, 450, tel_1);
    Character decoded = char(new String(encoded, StandardCharsets.UTF_8).codePointAt(0));
    text(decoded, 750, tel_1);
    tel_1 += 30;  tel_2 = 50;
  }
}