How this calculator works
Each byte is eight bits, and this page writes each byte as eight binary digits from the most significant bit to the least. A character is not necessarily one byte. UTF-8 uses one byte for plain English letters, two bytes for many accented letters and three or four bytes for other scripts and emoji. UTF-16 uses two bytes per code unit, so even a plain A is followed by a zero byte. Windows-1252 is a single-byte code page that covers Western European text only, and it fails on characters it has no byte for.
Formula
binary = each byte of the encoded text, written as eight bits and joined by the chosen separator. UTF-8 length varies from one to four bytes per character. UTF-16 little-endian writes the low byte then the high byte of each 16-bit code unit; the big-endian form reverses them, and the form with a byte order mark starts with FF FE. Windows-1252 uses one byte per character and cannot encode a character outside its table.
Worked example
Hi in UTF-8 is two bytes: H is 0x48, written 01001000, and i is 0x69, written 01101001, so with spaces the result is 01001000 01101001. The euro sign is 0x20AC. In UTF-8 it needs three bytes, E2 82 AC, written 11100010 10000010 10101100. In Windows-1252 the same sign is the single byte 0x80, written 10000000.
Advertisement
Frequently asked questions
Which encoding should I choose?
Use UTF-8 unless a system explicitly asks for something else. It is the standard for the web, handles every Unicode character and matches what most modern software stores. Choose UTF-16 for formats that specify it, and Windows-1252 only for old Western European files.
Why does the same text give different binary in different encodings?
Encoding is the mapping between characters and bytes, and each scheme has its own mapping. UTF-8 favours small ASCII letters, UTF-16 gives every code unit two bytes, and Windows-1252 has a single byte per character from its limited table. The characters are the same; the bytes are not.
Why do I get an error in Windows-1252?
That code page has no byte for characters outside Western European text, such as Chinese characters, Cyrillic letters or many emoji. The page names the first character it could not encode so you can remove it or switch to UTF-8.
What is the byte order mark for?
The two bytes FF FE at the start of UTF-16 little-endian tell a reader which byte order follows. Some programs add it and some do not, so it is a choice rather than part of the text. UTF-8 has an optional BOM too, but it is discouraged on the web.
Does a space count as a byte?
Yes. A space is an ordinary ASCII character, byte 0x20, written 00100000. Every character you type contributes at least one byte, and the separator you choose between bytes is only for display and is not part of the encoded text.