Beetwise

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.

  1. The character A has the code 65, which is 01000001.
  2. The bits are 01000001.

The code of each character in common use

The code of each character in common use
CharacterDecimalHexBinary
space320x2000100000
0480x3000110000
9570x3900111001
A650x4101000001
Z900x5A01011010
a970x6101100001
z1220x7A01111010
~1260x7E01111110

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 editor

Questions 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.