Measuring UTF-8 character size

Lets say I type something in Hindi and the outcome is listed below:

तीन व्याकितियों की औसत आयु ३३ वर्ष है.

In Hex View it will look like:

e0 a4 a4 e0 a5 80 e0 a4 a8 20 e0 a4 b5 e0 a5 8d e0 a4 af e0 a4 be e0 a4 95 e0 a4 bf e0 a4 a4 e0 a4 bf e0 a4 af e0 a5 8b e0 a4 82 20 e0 a4 95 e0 a5 80 20 e0 a4 94 e0 a4 b8 e0 a4 a4 20 e0 a4 86 e0 a4 af e0 a5 81 20 e0 a5 a9 e0 a5 a9 20 e0 a4 b5 e0 a4 b0 e0 a5 8d e0 a4 b7 20 e0 a4 b9 e0 a5 88 2e e0 a4 85 e0 a4 97 e0 a4 b0 20 e0 a4 89 e0 a4 a8 e0 a4 95 e0 a5 80 20 e0 a4 86 e0 a4 af e0 a5 81 20 e0 a5 a8 3a e0 a5 a9 3a e0 a5 aa 20 e0 a4 95 e0 a5 87 20 e0 a4 85 e0 a4 a8 e0 a5 81 e0 a4 aa e0 a4 be e0 a4 a4 20 e0 a4 ae e0 a5 87 e0 a4 82 20 e0 a4 b9 e0 a5 8b 2c e0 a4 a4 e0 a5 8b e0 a4 b9 20 e0 a4 89 e0 a4 a8 e0 a4 ae e0 a5 87 20 e0 a4 b8 e0 a5 87 20 e0 a4 b8 e0 a4 ac e0 a4 b8 e0 a5 87 20 e0 a4 ac e0 a5 9c e0 a5 87 20 e0 a4 95 e0 a5 80 20 e0 a4 86 e0 a4 af e0 a5 81 20 e0 a4 95 e0 a4 bf e0 a4 af e0 a5 8d e0 a4 a4 e0 a4 a8 e0 a5 87 20 e0 a4 b5 e0 a4 b0 e0 a5 8d e0 a4 b7 20 e0 a4 b9 e0 a5 8b e0 a4 97 e0 a5 80 3f

The main thing to notice here is that every hindi character is starting with the byte “E0”. This is basically a code point which identifies the code size of the UTF-8 character. The following table appropriate highlights it:

Binary    Hex          Comments
0xxxxxxx  0x00..0x7F   Only byte of a 1-byte character encoding
10xxxxxx  0x80..0xBF   Continuation bytes (1-3 continuation bytes)
110xxxxx  0xC0..0xDF   First byte of a 2-byte character encoding
1110xxxx  0xE0..0xEF   First byte of a 3-byte character encoding
11110xxx  0xF0..0xF4   First byte of a 4-byte character encoding

Reference: https://stackoverflow.com/questions/5290182/how-many-bytes-does-one-unicode-character-take/33349765#33349765

 

Leave a Reply

Your email address will not be published. Required fields are marked *