Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given the code below: define the three functions decimalToBinary, binaryAddition, and binaryToDecimal so that the program will be able to add binary numbers. The description

image text in transcribedimage text in transcribedimage text in transcribed

Given the code below: define the three functions decimalToBinary, binaryAddition, and binaryToDecimal so that the program will be able to add binary numbers. The description of each function is as follows: def decimalToBinary (n) : - This function takes a positive integer n>0 as an argument and returns a string of integers where each character of the string is a binary digit, 0 or 1 obtained by the conversion of the integer argument n to binary. You are not allowed to use the built-in function bin( ). For example, decimalToBinary(3) "11" decimalToBinary (123) "1111011" decimalToBinary(2312) "100100001000" binaryAddition(str1, str2): - This function takes two string arguments str 1 and str 2 representing two binary numbers and returns a string of integers whose characters are obtained by the addition of the two binary numbers in binary addition format. - How to add two binary numbers? Binary addition is like decimal addition, except that it carries on a value of 2 instead of a value of 10. 0+0=01+0=10+1=11+1=10(thisis0carry1)1+1+1=11(thisis1carry1) To add two binary numbers, we simply add together the corresponding digits in each binary number from right to left and if the sum is greater than what fits in a single digit, we carry a 1 into the next column. For example, 11111110101+111011010010 We start by the first column from the right: 1) First column: 1+1=0 (with carry 1 ) 2) Second column: +0+1 (carried) =1 (no carry) 3) Third column: 1+1+ no carry =0 (carry 1) 4) Fourth column: 0+1+1 (carried) =0 (carry 1) 5) Fifth column: 1+1+1 (carried) =1 (carry 1 ) 6) Sixth column: 1+1 (carried) =0 (carry 1) 7) Seventh column: 1 (carried) binaryAddition("110101", "11101") "1010010" binaryAddition("110101", "11101") "1010010" def binaryToDecimal(binStr): - This function takes a string binStr representing a binary number and converts it to decimal and returns the decimal number. For example, binaryToDecimal("10") 2 binaryToDecimal("10100") 20 binaryToDecimal("101110110010") 2994 binaryToDecimal("1111101110110000") 64432

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

Database Design Application Development And Administration

Authors: Michael V. Mannino

4th Edition

0615231047, 978-0615231044

More Books

Students also viewed these Databases questions

Question

What is the structure and scope of operations? LOP98

Answered: 1 week ago

Question

What are the main differences between rigid and flexible pavements?

Answered: 1 week ago

Question

What is the purpose of a retaining wall, and how is it designed?

Answered: 1 week ago

Question

How do you determine the load-bearing capacity of a soil?

Answered: 1 week ago

Question

what is Edward Lemieux effect / Anomeric effect ?

Answered: 1 week ago

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago