Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a Python function called binaryAdd( ) that takes in two strings of binary expansions, aand b, and returns the sum of the binary expansions

Create a Python function called binaryAdd( ) that takes in two strings of binary expansions, aand b, and returns the sum of the binary expansions as a string. For example,

 >> binaryAdd("10101", "101011") >> '1000000'

What I have so far ...

def binaryAdd(a, u): """ INPUT: a, u strings of 0's and 1's which are the binary reps of a and u OUTPUT: string representation of the binary sum """ c = 0 s = [] k = 0 if (len(a) > len(u)): k = len(a) for i in range (len(u), len(a)): u = u + '0' if (len(u) > len(a)): k = len(u) for i in range (len(a), len(u)): a = a + '0' else: k = len(a) for i in range (0, k): b = int(a[i]) n = int(u[i]) s.insert(i, (b + n + c) % 2) c = (b + n) // 2 if (c > 0): s.insert(len(s) + 1, c) return tuple(s)[::-1]

Thank you.

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_2

Step: 3

blur-text-image_3

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

Data Management Databases And Organizations

Authors: Richard T. Watson

3rd Edition

0471418455, 978-0471418450

More Books

Students also viewed these Databases questions