텍스트 → 2진수 / 16진수 변환
텍스트를 2진수, 16진수, 8진수, 10진수로 변환합니다.
2진수
Output will appear here...
16진수
Output will appear here...
8진수
Output will appear here...
10진수 (ASCII)
Output will appear here...
자주 묻는 질문
코드 구현
def text_to_binary(text: str, sep: str = " ") -> str:
"""Convert text to binary string (UTF-8 byte representation)."""
return sep.join(f"{byte:08b}" for byte in text.encode("utf-8"))
def binary_to_text(binary: str) -> str:
"""Convert binary string (space-separated 8-bit groups) back to text."""
groups = binary.strip().split()
byte_values = [int(g, 2) for g in groups]
return bytes(byte_values).decode("utf-8")
# Examples
original = "Hello, World!"
binary = text_to_binary(original)
print(f"Text : {original}")
print(f"Binary : {binary}")
print(f"Decoded : {binary_to_text(binary)}")
# Extended ASCII and Unicode
print()
for char in ["A", "z", "0", "@", "é", "中"]:
b = text_to_binary(char)
print(f" {char!r:6} -> {b}")
# Hexadecimal comparison
print()
for byte in "Hi".encode("utf-8"):
print(f" {byte:3d} 0x{byte:02X} {byte:08b}")Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.