Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE WRITE IN PYTHON Program a function binary_add (a,b) that computes the sum of the binary numbers a=(ai1,ai2,,a0)2 and b=(bj1,bj2,,b0)2 using the algorithm discussed in

PLEASE WRITE IN PYTHON

image text in transcribedimage text in transcribed

Program a function binary_add (a,b) that computes the sum of the binary numbers a=(ai1,ai2,,a0)2 and b=(bj1,bj2,,b0)2 using the algorithm discussed in lecture. No credit will be given to functions that employ any other implementation. The function can not use built-in functions that already perform some kind of binary representation or addition of binary numbers. For example, the function implementation can not use the functions bin() or int(a, base=2). The function should satisfy the following: 1. INPUT: - a - a string of the 0's and 1's that make up the first binary number. The string may contain spaces. - b - a string of the 0's and 1's that make up the first binary number. The string may contain spaces. 1. OUTPUT: - the string of 0 's and 1's that is the result of computing a+b. The string must be separated by spaces into blocks of 4 characters or less, beginning at the end of the string. EXAMPLE: \[ \begin{array}{l} \text { > binary_add( '10 1011', '11011') } \\ \text { "100 } 0110^{\prime} \end{array} \] def binary_add (a,b) : \#FIXME: Implement this method ALGORITHM | Addition of Binary Numbers Suppose a=(ak1,ak2,,a1,a0)2 and u=(uk1,uk2,,u1,u0)2 are the binary representations of decimal numbers a and u. 1. For i=0,1,,k1 perform ai+2ui plus any carry from the i1-st step. ai+ui+cmad2 PSEUDOCODE | Adding two numbers with base-2 expansions INPUT: a=(ak1,ak2,,a1,a0)2,u=(uk1,uk2,,u1,u0)2 OUTPUT: (sk1,sk2,,s1,s0)2 sum of a+u

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

Transactions On Large Scale Data And Knowledge Centered Systems Xxviii Special Issue On Database And Expert Systems Applications Lncs 9940

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Qimin Chen

1st Edition

3662534541, 978-3662534540

More Books

Students also viewed these Databases questions