Convert text to binary
A computer holds text as numbers.
Each character has a code, and the code of a plain ASCII character fits in 8 bits.
To convert text to binary, replace each character with its code, then write the code as 8 bits.
Try text to binary conversion in the bit editor
The character A, which has the code 65. Edit the expression or select a bit to flip it.
7
6
5
4
3
2
1
0
A
text · 8 bits
- binary
- 0b01000001
- value
- 65
Text to binary conversion step by step
Convert each character of the value above to its bits: The steps follow the value above.
- The character A has the code 65, which is 01000001.
- The bits are 01000001.
The code of each character in common use
| Character | Decimal | Hex | Binary |
|---|---|---|---|
| space | 32 | 0x20 | 00100000 |
| 0 | 48 | 0x30 | 00110000 |
| 9 | 57 | 0x39 | 00111001 |
| A | 65 | 0x41 | 01000001 |
| Z | 90 | 0x5A | 01011010 |
| a | 97 | 0x61 | 01100001 |
| z | 122 | 0x7A | 01111010 |
| ~ | 126 | 0x7E | 01111110 |
Where text to binary conversion is used
A serial link carries text as a stream of bytes.
A protocol that mixes text and numbers needs the code of each character.
A font file and a keyboard driver both map a code to a shape or a key.
Text to binary conversion: points to note
- The code of the digit 0 is 48, not 0. The character and the number differ.
- A capital letter and a small letter differ by 32. The letter A has the code 65 and the letter a has the code 97.
- ASCII covers the codes 0 to 127. A code above 127 belongs to UTF-8 or to a legacy code page.
- A UTF-8 character outside ASCII needs two to four bytes, so one character is not always one byte.
The full bit editor
The full editor holds many values, evaluates expressions across them, and reads live values from a serial port.
Open this value in the full editorQuestions about text to binary conversion
- What is A in binary?
- The letter A has the code 65. In 8 bits, 65 is 01000001.
- How many bits does one character need?
- A plain ASCII character needs 8 bits. A UTF-8 character outside ASCII needs 16, 24 or 32 bits.
- Why does the digit 0 have the code 48?
- ASCII puts the digits in one block that starts at 48, so the code of a digit is the digit plus 48.