An emoji in UTF-8 — binary and text
exam standardfour bytes, one character
Answer
11110000 10011111 10011000 10000000
Why this example is worth doing
A four-byte sequence, which breaks the assumption that one character is one byte in the most visible possible way. The page uses it to separate three ideas that are routinely conflated — code point, code unit and byte — and notes that this single character is one code point, four UTF-8 bytes and two UTF-16 code units. That is why string length is a question with several correct answers.
Try your own input in the Binary ⇄ text / ASCII. Convert text to binary and back, byte by byte, with the full UTF-8 breakdown.
How the answer is reached
UTF-8 encoding of 1 character
UTF-8 (RFC 3629): the leading byte says how many bytes follow, and every continuation byte starts 10.
| character | code point | decimal | hex | binary | template |
|---|---|---|---|---|---|
| 😀 | U+1F600 | 128512 | F0 9F 98 80 | 11110000 10011111 10011000 10000000 | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx |
| count | value |
|---|---|
| bytes | 4 |
| code points | 1 |
| UTF-16 code units | 2 |
Source: RFC 3629; WHATWG Encoding Standard