🛠️ToolsShed

Texte vers Binaire / Hexadécimal

Convertissez du texte en binaire, hexadécimal, octal et décimal.

Binaire
Output will appear here...
Hexadécimal
Output will appear here...
Octal
Output will appear here...
Décimal (ASCII)
Output will appear here...

Questions Fréquentes

Implémentation du Code

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.