Description
Encode one Unicode scalar into UTF-8 bytes and label each byte’s leading-bit pattern.
Unicode scalar values are distinct from UTF-8 bytes and UTF-16 code units. One scalar can require several units, and printable escape text is a representation of those values rather than execution or normalization of a string.
Encode one Unicode scalar into UTF-8 bytes and label each byte’s leading-bit pattern.
When to use this tool
Use Encoding: UTF-8 Single Scalar Leading Bit Layout when inspecting one scalar, code-unit layout or literal escape representation.
How to use the tool and how it works
- Enter codepoint. Use the units and conventions below.
- Run the tool. Correct any format, range, or cross-field input error before interpreting the output.
- Read result. Expand result to inspect the returned fields.
Require a Unicode scalar codepoint. Encode its UTF-8 bytes and return the corresponding bit-pattern labels: 0xxxxxxx for a one-byte scalar, 110xxxxx/1110xxxx/11110xxx for its multibyte lead, and 10xxxxxx for each continuation byte.1
UTF-8 encodes Unicode scalars using constrained one-to-four-octet sequences; an isolated field is not a complete stream validation.2
| Input field | Meaning and units | Accepted input |
|---|---|---|
| codepoint | Unicode scalar integer, excluding the surrogate interval U+D800–U+DFFF. | Required. Safe integer. |
| Output field | Interpretation | Returned shape |
|---|---|---|
| result | Object containing the named calculated members below. | Required. Object. |
| result.bytes | Bytes | Calculated result member: array. |
| result.leadingBitLayout | Leading Bit Layout | Calculated result member: array. |
{
"input": {
"codepoint": 8364
},
"output": {
"result": {
"bytes": [
226,
130,
172
],
"leadingBitLayout": [
"1110xxxx",
"10xxxxxx",
"10xxxxxx"
]
}
}
} Limitations and assumptions
- Surrogate code points are not Unicode scalars. This inspects one scalar's byte layout, not string normalization, grapheme boundaries or a full-stream validity check.
- Outputs are nested inside result. Inputs must satisfy both the field types and the cross-field conditions above. Invalid input causes an error; a successful false flag or documented placeholder is a different result.
- Numeric calculations use binary floating point unless exact decimal-integer arithmetic is explicitly stated. No hidden measurement tolerance or decimal rounding is added; nonfinite or out-of-contract results are rejected. Numeric signed-zero results are exported as zero.
Alternative or Complementary methods
Use a full Unicode encoder or parser when processing strings, and handle normalization, graphemes and context-specific escaping separately.
References
-
Calculation and input contract: encode/utf8-single-scalar-leading-bit-layout — tool.io
-
UTF-8: RFC 3629 — Internet Engineering Task Force
Similar or alternative tools
- Encoding: UTF-8 Continuation Byte From Payload
Return byte = 128+payload, setting the UTF-8 continuation prefix bits to 10.
- UTF-8 BOM Octet Triplet
Return octets [239,187,191] when include is true and an empty array otherwise.