How ASCII Text to Binary Conversion Works
At the fundamental hardware layer of all digital computers, information is stored and processed exclusively in binary bits (states of 0 or 1 representing low and high voltage potentials). To represent human-readable text—such as letters, punctuation marks, and control commands—the computing industry adopted standard character encodings like ASCII (American Standard Code for Information Interchange) and its modern extension UTF-8.
The Mathematical Conversion Process
Converting a human-readable text string into binary involves a two-stage transformation:
- Character Code Mapping (Text → Decimal Base-10): Each character is mapped to its defined numerical value according to the character encoding standard. For example, uppercase
'A'maps to integer65, and lowercase'z'maps to122. - Base-10 to Base-2 Decomposition (Decimal → Binary 8-Bit Byte): The decimal integer is converted into binary by determining the sum of powers of 2:
65 = (1 × 2⁶) + (1 × 2⁰) = 64 + 1 → 01000001₂
'H' → Decimal 72 = 01001000₂ (64 + 8)
'e' → Decimal 101 = 01100101₂ (64 + 32 + 4 + 1)
'y' → Decimal 121 = 01111001₂ (64 + 32 + 16 + 8 + 1)
Result:
01001000 01100101 01111001UTF-8 Multi-Byte Binary Encoding Rules
While standard ASCII uses 7 bits padded into 1 byte (0xxxxxxx), the universal UTF-8 standard supports over 1.1 million Unicode characters across multiple bytes:
- 1-Byte Range (U+0000 to U+007F): Standard ASCII characters formatted as
0xxxxxxx(e.g. 'A' =01000001). - 2-Byte Range (U+0080 to U+07FF): Accented Latin, Greek, Arabic formatted as
110xxxxx 10xxxxxx. - 3-Byte Range (U+0800 to U+FFFF): Asian CJK scripts, currencies (like '€' =
11100010 10000010 10101100). - 4-Byte Range (U+10000 to U+10FFFF): Emojis, mathematical symbols, historic scripts (like '🚀' =
11110000 10011111 10011000 10000000).
Converting Text to Binary in Code
const text = "Hi";
const binary = Array.from(text)
.map(c => c.charCodeAt(0).toString(2).padStart(8, '0'))
.join(' ');
console.log(binary); // "01001000 01101001"text = "Hi"
binary = ' '.join(format(ord(c), '08b') for c in text)
print(binary) # 01001000 01101001