Text to Binary Converter

Convert text to binary, hex, decimal or octal bytes, and back — UTF-8, UTF-16 or ASCII, without leaving the page.

Nothing leaves your browser: the conversion happens here, in the page.

Bytes
01000011 01111010 01100101 11000101 10011011 11000100 10000111 00100001 00100000 11110000 10011111 10010001 10001011

13 bytes of UTF-8, written as binary groups.

Runs in your browser. Nothing you enter is sent anywhere.

How to use it

  1. Pick Encode to turn text into bytes, or Decode to turn bytes back into text.
  2. Pick how each byte is written: Binary, Hex, Decimal or Octal.
  3. Pick the text encoding: UTF-8, UTF-16 or ASCII. UTF-8 is what the web, JSON and most files use.
  4. When encoding, pick what goes between bytes: Spaces, None or Commas.
  5. Type into Text (or paste into Bytes when decoding). The result appears under Bytes or Text with Copy, and the line below counts the bytes, such as 3 bytes of UTF-8, written as binary groups.

Swap moves the result into the input and flips the direction, so a round trip is one click. The conversion runs in the page; nothing leaves your browser.

Examples

Plain ASCII text, Hi!, with Encode, Binary, UTF-8 and Spaces:

01001000 01101001 00100001

Each character below 128 is one byte, so UTF-8 and ASCII give the same bits here.

The page’s sample, Cześć! 👋, with Encode and Hex, first in UTF-8 (13 bytes), then in UTF-16 (18 bytes):

43 7a 65 c5 9b c4 87 21 20 f0 9f 91 8b
00 43 00 7a 00 65 01 5b 01 07 00 21 00 20 d8 3d dc 4b

In UTF-8, ś and ć take two bytes each and the emoji four. In UTF-16 every character takes two bytes, and the emoji, past U+FFFF, takes a surrogate pair: d8 3d dc 4b.

Bytes copied from a C array, 0x63,0x61,0x66,0xc3,0xa9, with Decode, Hex and UTF-8, give café. The same word saved as Latin-1, 63 61 66 e9, is rejected:

Invalid UTF-8: byte 4 starts a broken sequence.

In UTF-8, e9 opens a three-byte sequence, and nothing follows it. In Latin-1 it means é on its own.

café with Encode and ASCII fails with ASCII stops at 127, and "é" (U+00E9) at character 4 is above it.

Good to know

  • A character isn’t a byte. UTF-8 (RFC 3629) writes code points up to U+007F in one byte, up to U+07FF in two, up to U+FFFF in three and the rest in four. So € is e2 82 ac, and a 280-character post can be well over 280 bytes.
  • UTF-16 here is big-endian with no byte order mark, high byte first: H is 00 48. Files that Windows calls “Unicode” are usually UTF-16LE with a BOM, so their bytes come in the other order (ff fe 48 00) and won’t decode correctly here.
  • ASCII is 7-bit: codes 0 to 127 and nothing else. Latin-1 and Windows-1252 are sometimes called “extended ASCII”, but they’re different encodings, and their bytes above 127 aren’t valid UTF-8 on their own.
  • Decoding takes messy input. Groups may be separated by any run of spaces, commas, tabs or line breaks, and may carry 0x (hex) or 0b (binary). They needn’t be padded: 1001000 1101001 decodes to Hi. One unseparated run splits every 8 binary, 2 hex or 3 octal digits, which is what None writes, so 48656 is rejected: 5 hex digits with no separators aren't a whole number of bytes, at 2 digits a byte. Decimal has no fixed width, so it needs separators.
  • UTF-8 decoding is strict. It refuses what new TextDecoder('utf-8', { fatal: true }) refuses: a stray continuation byte, a sequence cut short, an overlong form, an encoded surrogate, or a byte no sequence starts with, f5 to ff. The error names the byte where the broken sequence starts, instead of a silent U+FFFD.
  • Encoded output is padded: binary to 8 digits, hex to 2 (lowercase), octal to 3; decimal isn’t padded.
  • Whitespace is data. The input isn’t trimmed, so a trailing line break encodes as 00001010 (0a). Input is limited to 50,000 characters.

Questions

How do I convert text to binary?

Encode the text to bytes, then write each byte as eight bits: pick Encode, Binary and UTF-8. In Python, ' '.join(f'{b:08b}' for b in 'Hi'.encode()) gives 01001000 01101001; in JavaScript, [...new TextEncoder().encode(text)].map(b => b.toString(2).padStart(8, '0')).join(' ').

How do I convert binary to text?

Pick Decode and Binary, paste the bits, and read Text. Each group of eight bits is one byte, and the bytes are then read as UTF-8. In Python, bytes(int(b, 2) for b in s.split()).decode() does the same.

How do I convert text to hex?

Pick Encode and Hex: Hi is 48 69. In a shell, printf 'Hi' | xxd -p prints 4869, and in Python 'Hi'.encode().hex() returns the same.

Is ASCII to binary the same as UTF-8 to binary?

Yes, for characters 0 to 127: UTF-8 was designed so every ASCII byte means the same thing in both. They differ only past 127, where ASCII has no code at all and UTF-8 uses two to four bytes.