Question
PYTHON: How do I split up the binary string into chunks of 8 so that they are converted from binary to ASCII characters? For example
PYTHON: How do I split up the binary string into chunks of 8 so that they are converted from binary to ASCII characters? For example "0011101000101001" would be eventually converted to ":)" . The code I have below is what I currently have. It currently only works for binary strings of 8. argv[1] is the text file it is reading from and argv[2] is basically just 8.
import sys filename=sys.argv[1] length = int(sys.argv[2]) message_data = open(filename, "r") message_text = message_data.read() if len(message_text) == 0: sys.exit(1) a= message_text.replace(',','') a= ''.join(a.split()) conversion_list =[128, 64, 32, 16, 8, 4, 2, 1] dec=0 for position, digit in enumerate((a)): dec += conversion_list[position]* int(digit) print("Decimal is ",dec) e=chr(dec)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started