AbdulMajeed776 commited on
Commit
fb28dd9
·
verified ·
1 Parent(s): 1daf99c

Create binary_utils.py

Browse files
Files changed (1) hide show
  1. binary_utils.py +10 -0
binary_utils.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ def binary_to_text(binary_data):
2
+ # Converts binary (e.g., 0s and 1s) into ASCII text
3
+ try:
4
+ n = int(binary_data, 2)
5
+ return n.to_bytes((n.bit_length() + 7) // 8, 'big').decode()
6
+ except Exception:
7
+ return "Invalid binary input"
8
+
9
+ def text_to_binary(text):
10
+ return ' '.join(format(ord(c), '08b') for c in text)