🛠️ToolsShed

Teks ke Biner / Heksadesimal

Mengonversi teks ke representasi biner, heksadesimal, oktal, dan desimal.

Biner
Output will appear here...
Heksadesimal
Output will appear here...
Oktal
Output will appear here...
Desimal (ASCII)
Output will appear here...

Pertanyaan yang Sering Diajukan

Implementasi Kode

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.