Question: The following is an algorithm to add two non-negative integers A and B. A and B are binary numbers. They have been inputted as strings.

The following is an algorithm to add two non-negative integers A and B.

function add(A, B): while B is greater than 0: U = A

A and B are binary numbers. They have been inputted as strings.

Given the initial values of A and B write an efficient C++ program to find out the number of times the while loop of the algorithm is repeated.

function add(A, B): while B is greater than 0: U = A XOR B V = A AND B A = U B = V * 2 return A function add(A, B): while B is greater than 0: U = A XOR B V = A AND B A = U B = V * 2 return A

Step by Step Solution

3.55 Rating (162 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To solve the problem of counting the number of times the while loop is repeated in the given algorit... View full answer

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 Programming Questions!