Convert text to binary code and binary back to text.
This converts text into its binary representation and back again. Each character is mapped to a number by a character encoding, and that number is written in base 2. For ordinary English text using ASCII, each character becomes eight bits.
The word Hi:
H is ASCII 72. In binary: 64 + 8 = 01001000i is ASCII 105. In binary: 64 + 32 + 8 + 1 = 0110100101001000 01101001To convert a byte back, add up the place values where a bit is 1. Reading 01001000 from the left: 128 x 0, 64 x 1, 32 x 0, 16 x 0, 8 x 1, 4 x 0, 2 x 0, 1 x 0 = 72.
| Bit position | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
|---|---|---|---|---|---|---|---|---|
| Value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
An 8-bit byte represents 0 to 255, which is 256 distinct values. Useful anchors for reading ASCII: uppercase letters run 65-90, lowercase 97-122, and digits 48-57. Uppercase and lowercase differ by exactly 32, which is a single bit — the sixth. Flipping that one bit changes case, which is why case conversion is so cheap in low-level code.
ASCII covers only 128 characters, which is not remotely enough for the world's writing systems. UTF-8 extends it using a variable number of bytes per character while keeping the first 128 identical to ASCII, so plain English text is byte-for-byte the same in both.
| Character range | Bytes | Example |
|---|---|---|
| ASCII (U+0000-U+007F) | 1 | A, z, 7 |
| Latin accented, Greek, Cyrillic | 2 | e-acute, alpha |
| CJK, most other scripts | 3 | Chinese, Japanese, Korean |
| Emoji, rare scripts | 4 | Emoji characters |
The leading bits of the first byte announce how many bytes follow, which is what makes UTF-8 self-synchronising: a decoder that starts mid-stream can find the next character boundary. This is why a single emoji can produce 32 bits of binary while a letter produces 8, and why "number of characters" and "number of bytes" are different questions.
Digital circuits distinguish two states reliably — voltage present or absent, charge stored or not — and two states are far easier to keep unambiguous than ten would be. Everything above that is a convention built on top: numbers, text, images and instructions are all sequences of bits given meaning by whatever is reading them. The same 01001000 is the letter H, the number 72, or a machine instruction, depending entirely on context.
Binary is verbose, so programmers usually write the same values in hexadecimal, where each digit represents exactly four bits.
| Decimal | Binary | Hex |
|---|---|---|
| 10 | 00001010 | 0A |
| 72 | 01001000 | 48 |
| 255 | 11111111 | FF |
Grouping bits in fours and converting each group is far quicker than working in binary directly, which is why colour codes, memory addresses and byte dumps are all written in hex.
Eight for any ASCII character. In UTF-8, characters outside ASCII take two, three or four bytes — so 16, 24 or 32 bits. An emoji is usually four bytes.
Split the string into groups of eight, then for each group add the place values of the positions holding a 1, reading 128, 64, 32, 16, 8, 4, 2, 1 from the left. Look the resulting number up in an ASCII table.
Because ASCII was laid out so that the two cases differ by a single bit — the one worth 32. Flipping that bit converts between cases, which made case handling extremely cheap on early hardware.
255, since eight bits give 256 values counting from zero. Two bytes reach 65,535 and four bytes reach 4,294,967,295, which is why 32-bit limits appear so often in older software.
Yes. Text is encoded as UTF-8 before conversion, so accented letters, non-Latin scripts and emoji all convert correctly — they simply produce more bytes per character than plain ASCII does.