Binary ⇄ Text Converter

Characters to bits and bits back to characters — ASCII and UTF-8, with the code point and byte layout for each one.

Note:

Not what you were looking for?

Converting numbers between bases (binary, decimal, hex, octal) → Number base converter. Converting negative numbers → Two’s complement converter.

Text

Binary

Settings

Encoding

Separator

Invalid bytes

Browsers replace invalid bytes with � by default. Reject shows you exactly where the byte stream breaks.

Binary

01001000 01101001

characters (code points): 2 · bytes: 2 · UTF-16 code units: 2

UTF-8 encoding of 2 characters

UTF-8 (RFC 3629): the leading byte says how many bytes follow, and every continuation byte starts 10.

UTF-8 encoding of 2 characters — columns character, code point, decimal, hex, binary, template
charactercode pointdecimalhexbinarytemplate
HU+00487248010010000xxxxxxx
iU+006910569011010010xxxxxxx
Three different numbers; the UI must show all three — UTF-8 encoding of 2 characters
countvalue
bytes2
code points2
UTF-16 code units2

Source: RFC 3629; WHATWG Encoding Standard

Note:

Notation used on this page

  • Bytes are written most significant bit first.
  • The separator between groups of eight is for reading and is not part of the data; a copied bit string has no separators.
  • Hex is upper case. Code points are written U+ followed by at least four upper-case hex digits.

Start from a worked example

What binary text actually is

A character is a number. Unicode assigns every character a code point — the letter H is U+0048, decimal 72 — and a character encoding is the rule that turns that code point into bytes. A byte, also called an octet, is eight bits, and a bit is one digit in base 2. So the letter H under ASCII is the single byte 01001000, and under UTF-8 it is the same byte, because UTF-8 was designed to agree with ASCII over the first 128 code points.

There is no such thing as “the” binary for a character until you say which encoding you mean. The character é is one code point, U+00E9, and it is one byte in Latin-1 and two bytes — C3 A9 — in UTF-8. This page always states the encoding it used, and shows the code point, the byte and the eight bits of every byte rather than presenting a lookup you have to trust.

ASCII

ASCII defines 128 code points, U+0000 to U+007F, in four blocks of 32: control codes 0–31, punctuation and digits 32–63, upper-case letters and a few symbols 64–95, and lower-case letters 96–127. Seven bits are enough for all of them, which is why ASCII is a 7-bit code.

The two facts exam questions actually ask for: A = 65 = 01000001 and a = 97 = 01100001. The difference is exactly bit 5 — decimal 32, 0x20 — so case conversion is a single XOR: 65 ⊕ 32 = 97.

The eighth bit of a byte was originally free, and the commonest thing to do with it was to make it a parity bit. That history is on the parity and checksum page: 7-bit ASCII plus one parity bit is a byte.

A printable ASCII table

Every printable ASCII character, from space (32) to tilde (126), with its decimal value, its hexadecimal value and its eight bits. This table is in the page’s HTML rather than drawn by script, so it prints and it is readable without JavaScript.

Printable ASCII, U+0020 to U+007E
CharacterDecimalHexBinary
space322000100000
!332100100001
"342200100010
#352300100011
$362400100100
%372500100101
&382600100110
'392700100111
(402800101000
)412900101001
*422A00101010
+432B00101011
,442C00101100
-452D00101101
.462E00101110
/472F00101111
0483000110000
1493100110001
2503200110010
3513300110011
4523400110100
5533500110101
6543600110110
7553700110111
8563800111000
9573900111001
:583A00111010
;593B00111011
<603C00111100
=613D00111101
>623E00111110
?633F00111111
@644001000000
A654101000001
B664201000010
C674301000011
D684401000100
E694501000101
F704601000110
G714701000111
H724801001000
I734901001001
J744A01001010
K754B01001011
L764C01001100
M774D01001101
N784E01001110
O794F01001111
P805001010000
Q815101010001
R825201010010
S835301010011
T845401010100
U855501010101
V865601010110
W875701010111
X885801011000
Y895901011001
Z905A01011010
[915B01011011
\925C01011100
]935D01011101
^945E01011110
_955F01011111
`966001100000
a976101100001
b986201100010
c996301100011
d1006401100100
e1016501100101
f1026601100110
g1036701100111
h1046801101000
i1056901101001
j1066A01101010
k1076B01101011
l1086C01101100
m1096D01101101
n1106E01101110
o1116F01101111
p1127001110000
q1137101110001
r1147201110010
s1157301110011
t1167401110100
u1177501110101
v1187601110110
w1197701110111
x1207801111000
y1217901111001
z1227A01111010
{1237B01111011
|1247C01111100
}1257D01111101
~1267E01111110

UTF-8

UTF-8 encodes a code point in one to four octets according to its magnitude. The lead octet says how many octets follow, and every continuation octet begins 10.

The UTF-8 octet templates, from RFC 3629
Code point rangeOctets
0000 0000 – 0000 007F0xxxxxxx
0000 0080 – 0000 07FF110xxxxx 10xxxxxx
0000 0800 – 0000 FFFF1110xxxx 10xxxxxx 10xxxxxx
0001 0000 – 0010 FFFF11110xxx 10xxxxxx 10xxxxxx 10xxxxxx

Two properties follow, and together they are why UTF-8 won. Every ASCII byte is unchanged, so ASCII text is already valid UTF-8. And no continuation octet can be mistaken for a lead octet, so a decoder that starts in the middle of a stream can resynchronise by scanning forward to the next byte that is not 10xxxxxx.

What UTF-8 forbids

  • Surrogates. U+D800 to U+DFFF exist only as a UTF-16 mechanism and are not encodable.
  • Code points above U+10FFFF. The four-octet form can express more than Unicode defines; the excess is invalid.
  • Overlong forms. A code point must use the shortest template that fits it.

RFC 3629 is explicit about why the third rule matters: “a naive implementation may decode the overlong UTF-8 sequence C0 80 into the character U+0000 … Implementations of the decoding algorithm above MUST protect against decoding invalid sequences.” The WHATWG Encoding Standard then fixes what a browser does instead: emit U+FFFD, and “no other behavior is permitted”. This page’s decoder follows that rule by default and offers a strict mode that reports the offset where the byte stream breaks.

Counting: characters, bytes, code units, graphemes

Four different numbers describe the same string, and confusing them is the source of most encoding bugs.

Four counts of the same two strings
TextCode pointsUTF-8 bytesUTF-16 code unitsGraphemes
Café 😀61076
👨‍👩‍👧51881

"😀".length is 2 in JavaScript, because String.length counts UTF-16 code units, not characters. A field that allows “20 characters” and a database column that allows “20 bytes” are not the same field.

Notation used on this page

  • Bytes are written most significant bit first.
  • Groups of eight are separated by a space for reading; the space is not part of the data and a copied bit string has none.
  • Hexadecimal is upper case.
  • Code points are written U+ followed by at least four upper-case hexadecimal digits.

Sources

Worked examples