Hongmu Notes

🗄️ Convert string to binary

Enter a piece of text and get a binary string of 8 bits each.

Convert string to binary

Instructions for use

  • Encoded according to UTF-8: 1 byte for English numbers, 3 bytes for Chinese characters, 4 bytes for emoticons
  • Output a continuous 8-digit fixed-length string, which can be restored by pasting it back into "Binary to String"
  • All is done locally in the browser, and the input content will not be uploaded.

Convert text to 8-bit fixed-length binary

The biggest advantage of the fixed-length format is that it is predictable: no matter what the content is, the output length is 8 times the number of bytes, and the parsing end can be restored by dividing it according to the fixed step size, without the need for special case processing.

📌 Predictable length

Output length = number of bytes multiplied by 8, always a multiple of 8. The actual measured Welcome is 56 bits, Hi is 16 bits, and "Middle" is 24 bits. No additional zero padding or truncation is required.

⚙️ Processing on the parsing side

stepspractice
VerificationNumber of digits is a multiple of 8
cutgroup of 8 bits
restoreByte sequence decoded as UTF-8

🧭 Points to note when pasting

The fixed-length string is very long and may be truncated when pasted into an input box with a length limit; when an exception occurs at the end of the restoration result, first check whether the number of digits is a multiple of 8, and then confirm whether the tail segment has been truncated.

📌 Reverse character composition using digits

Divide the number of digits by 8 to get the number of bytes; combined with the general content of the text (mainly English or Chinese), you can determine whether invisible characters are mixed in. This is a practical way to quickly locate input problems.

All keywords and tutorials 12

❓ FAQ

Will the output have leading zeros lost?
No. Each byte is complemented by 8 bits, and even if the value is small (for example, A is 01000001) the leading 0s will be kept intact. This is the meaning of the fixed-length format.
What are the advantages and disadvantages compared with hexadecimal?
The number of binary digits is 4 times that of hexadecimal, which takes up more space; but it is more intuitive and suitable for teaching and bit-by-bit verification. Hexadecimal is usually used for actual storage.
How to estimate the length of the result
The number of digits in pure English = the number of characters multiplied by 8; when it contains Chinese, it is calculated as 3 bytes per character, when it contains emoticons it is calculated as 4 bytes per character, and the status line will directly give the actual number of bytes and digits.