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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!