Unicode - A character is not a char!

Unicode - A character is not a char!


Unicode

A character is not a char...

Codepoint

Unicode Transformation Format 8 (UTF-8)

/* source: https://www.unicode.org/versions/Unicode17.0.0/core-spec/chapter-3/#G27506 */

        1 byte                2 bytes                      3 bytes                             4 bytes
<---------------------|----------------------|-----------------------------------|------------------------------->
    U+0000 .. U+007F
                          U+0080 .. U+07FF
                                                         U+0800 .. U+0FFF
                                                         U+1000 .. U+CFFF
                                                         U+D000 .. U+D7FF
                                                         U+E000 .. U+FFFF
                                                                                         U+10000  .. U+3FFFF
                                                                                         U+40000  .. U+FFFFF
                                                                                         U+100000 .. U+10FFFF

UTF-8 Encoding/Decoding

/* source: https://www.rfc-editor.org/info/rfc3629/#ref-UNICODE */

Char. number range  |        UTF-8 octet sequence
   (hexadecimal)    |              (binary)
--------------------+---------------------------------------------
0000 0000-0000 007F | 0xxxxxxx
0000 0080-0000 07FF | 110xxxxx 10xxxxxx
0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
character  =>'δΈ–'
codepoint  => U+4E16
encodedLen => 3 bytes /* U+0800 <= 0x4E16 <= U+FFFF */

binary  => '0b100111000010110'
binary  => '     100        111000        010110'
pattern => 1110|xxxx     10|xxxxxx     10|xxxxxx
encoded => 1110|0100     10|111000     10|010110
------------------------------------------------
UTF-8   =>  11100100      10111000      10010110

Unicode Library