ai_model / binary_utils.py
AbdulMajeed776's picture
Create binary_utils.py
fb28dd9 verified
raw
history blame
343 Bytes
def binary_to_text(binary_data):
# Converts binary (e.g., 0s and 1s) into ASCII text
try:
n = int(binary_data, 2)
return n.to_bytes((n.bit_length() + 7) // 8, 'big').decode()
except Exception:
return "Invalid binary input"
def text_to_binary(text):
return ' '.join(format(ord(c), '08b') for c in text)