Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python Bitstring question: 1. Define and implement a function called processBits

ID: 3684088 • Letter: P

Question

Python Bitstring question:

1. Define and implement a function called processBitstrings(first, second) that takes two bitstrings (first and second)

Assume that the bits are numbered from right-to-left starting from 0. So, bit i is in the i-th column from the right.

a. Define the bitsum as the sum of the i-th bits of a pair (or set) of bitstrings.

b. Define the bitsum maximum (bitsumMax) to be the highest of all the bitsums.

c. Define the bitsum minimum (bitsumMin) to be the lowest non-zero value of all the bitsums.

The function returns a bitstring as follows: the i-th digit of the return value is: 1 if the i-th bitsum is equal to the bitsum maximum or the bitsum minimum.

0 otherwise.

I really appreciate your help! thanks

Explanation / Answer

Here's the code for this problem : https://pastebin.mozilla.org/8865747

The way I approached this question was quite simple. You simply need to write a function for calculating the bitsum of 2 bits given the 2 strings as input and an index i. The answers are either 0, 1 or 2. Then you need to write a function to iterate over all the bits and calculate the bitsumMax and bitsumMin. This will have to be O(N) since one pass over the string is necessary for finding out these 2 numbers. Once that's done, it's very easy to use these functions we've written to reach the solution.

Let me know if you have any questions or doubts with this.