Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi there! I am stuck on this Python coding homework question. Below is a snip of the requirements and a snip of what was given

Hi there! I am stuck on this Python coding homework question. Below is a snip of the requirements and a snip of what was given in the editor.

image text in transcribedimage text in transcribedimage text in transcribed

Exercise 8.3.9: Text to Binary 5 points In this exercise, you'll write a program that encodes written text into binary data! As we've seen, every character can be represented by a string of 8 bits, or a byte. For example, the character A maps to the decimal value of 6510 by the ASCII standard, and the binary value of 6510 is 010000012 We can easily go from a character to the corresponding ASCII integer value using the Python method ord(letter). For example, the following code: text = "Hello" letter - text[0:1] numeric value = ord(letter) print(letter + + str(numeric_value)) Will print out H --> 72 Using the decimal_to_binary function provided, write a function text_to_binary that takes a String of text, converts each character into its ASCII numerical value, converts each numerical value into its binary equivalent, and returns a string representing the translated text. For example: text_to_binary("HI") Should return: "0100100001001001" To see why, let's examine this String: "HI" is made of 2 characters. The first character is 'H' The ASCII value of 'H' is 72 decimal_to_binary (72) returns 01001000" The next character is l' The ASCII value of l' is 73 decimal_to_binary (73) returns 01001001" The resulting String is these two binary strings put together, resulting in "0100100001001001" 8.3.9: Text to Binary Save Submit This program encodes user input into binary data! Your job is to write the textToBinary function - def text_to_binary(text): # Write this method! # For every character in the text, # convert the character into its ASCII decimal encoding # then convert that decimal value into its equivalent binary encoding # and combine each binary encoding to get the resulting binary string # Converts a given decimal value into an 8 bit binary value - def decimal_to_binary (decimal_value): binary_base = 2 num_bits_desired = 8 binary_value = str(bin(decimal_value)) [2:] while len(binary_value)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions