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.

UTF-8 encoding of 1 character — columns character, code point, decimal, hex, binary, template
charactercode pointdecimalhexbinarytemplate
😀U+1F600128512F0 9F 98 8011110000 10011111 10011000 1000000011110xxx 10xxxxxx 10xxxxxx 10xxxxxx
Three different numbers; the UI must show all three — UTF-8 encoding of 1 character
countvalue
bytes4
code points1
UTF-16 code units2

Source: RFC 3629; WHATWG Encoding Standard

Compare with

Open this example in the Binary ⇄ text / ASCII

The field arrives filled in with this example’s input.

Note:

Notation this page assumes

  • Bit strings are written most significant bit first, and bit 0 is the least significant bit.
  • A width is stated explicitly wherever it changes the answer; nothing is silently sign-extended or truncated.
  • ASCII is the 7-bit set padded to one byte; UTF-8 is shown byte by byte, so a non-ASCII character is more than eight bits.

Sources

  • ANSI X3.4 / ISO-IEC 646, the ASCII character set
  • The Unicode Standard, Annex on the UTF-8 encoding form