Understanding the text to binary, hex and decimal bytes converter — concept and principle
Computers store text as numbers. This converter shows exactly which bytes a piece of text becomes when encoded in UTF-8, the encoding used by most web pages, and writes those bytes three ways: hexadecimal, binary and decimal. It is useful for learning how encoding works, debugging garbled characters, checking byte limits in databases or protocols, and teaching number bases.
How it is calculated
- Encode the text as UTF-8, giving a list of bytes, each a number from 0 to 255.
- Hex: write each byte in base 16 with two digits (00–FF).
- Binary: write each byte in base 2 with eight digits (00000000–11111111).
- Decimal: write each byte in base 10.
- Byte length: count the bytes, which can differ from the number of characters.
The principle
Unicode gives every character a number called a code point, such as U+0048 for H and U+C138 for 세. UTF-8 stores code points with a variable number of bytes: U+0000–U+007F (ASCII) use 1 byte, up to U+07FF use 2 bytes, up to U+FFFF (which includes all Hangul syllables) use 3 bytes, and the rest, such as most emoji, use 4 bytes. ASCII text is therefore identical in UTF-8, which is the main reason UTF-8 became the web's standard. Hex is popular for showing bytes because one hex digit is exactly four bits, so two digits always describe one byte.
Worked example
- Input: "Hi!".
- H is code point 72, i is 105, ! is 33; all are ASCII, so each is one UTF-8 byte.
- Hex: 72 = 4 × 16 + 8 = 48, 105 = 6 × 16 + 9 = 69, 33 = 2 × 16 + 1 = 21, giving 48 69 21.
- Binary: 72 = 64 + 8 = 01001000, 105 = 64 + 32 + 8 + 1 = 01101001, 33 = 32 + 1 = 00100001, giving 01001000 01101001 00100001.
- Decimal: 72 105 33; byte length 3.
How to read the result
For plain English text the byte length equals the number of characters. Each Korean syllable adds three bytes, so "세계" is 6 bytes, and an emoji such as a smiley face is 4 bytes. In UTF-8 a byte starting with 0 is a single ASCII character, a byte starting with 10 is a continuation byte, and a lead byte starting with 110, 1110 or 11110 announces a 2-, 3- or 4-byte character. This makes it easy to spot where a multi-byte character begins in a hex dump.
Common mistakes
- Assuming one character is always one byte, which fails for Korean, accented letters and emoji.
- Dropping leading zeros in binary; each byte should show eight digits.
- Confusing a code point (U+C138) with its UTF-8 bytes (EC 84 B8).
Frequently asked questions
Why does a Korean character take 3 bytes?
Hangul syllables lie between U+AC00 and U+D7A3, above U+07FF, so UTF-8 needs three bytes to store them.
What is the byte for a space?
A space is decimal 32, hex 20, binary 00100000.
How many characters fit in a 255-byte field?
255 ASCII characters, but only 85 Korean syllables in UTF-8.
Sources: IETF RFC 3629, UTF-8, a transformation format of ISO 10646 · The Unicode Consortium, The Unicode Standard (Chapter 3, Conformance)