Question: Please help me write this in Python. Thank you. Your program should use the bit string representation of sets to perform union, intersection, and complement

Please help me write this in Python. Thank you.
Your program should use the bit string representation of sets to perform union, intersection, and complement operations.
Your program should NOT use the built-in set operations of the programming language.
"Represent a subset A of U with the bit string of length n, where the ith bit in this string is 1 if ai belongs to A and is 0 if ai does not belong to A."
In this program, you can assume that the universal set U={a,b,c,d,e,f,g,h}.
The bit string representation of the universal set U will be 11111111.
Your program will prompt the user to enter two subsets of U.
For example, if A={a,b,c}, the user will enter 11100000.
If B={c,d,e}, the user will enter 00111000.
Your program should use the bitwise operations, such as AND, OR, COMPLEMENT, of the programming language to calculate and print the bit string representation of
AB
AB
the complement of A
The following is a sample execution:
Enter the bit string representation of A: 11100000
Enter the bit string representation of B: 00111000
A union B ,=11111000
A intersect B ,=00100000
The complement of A=00011111
When you process the user input, you should "squeeze" all 8 digits into a single unsigned integer, instead of into an array of 8 integers.
This way, the value of each bit indicates if an element appears in the subset.
The 8 bits of a single unsigned integer (not an array of 8 integers)
A sample algorithm to put the 8 bits of user input into an unsigned integer:
Initialize the unsigned integer to 0.
If the 1st digit of user input is "1", OR | that unsigned integer with 128.
If the 2nd digit of user input is "1", OR | that unsigned integer with 64.
If the 3rd digit of user input is "1", OR | that unsigned integer with 32.
If the 4th digit of user input is "1", OR | that unsigned integer with 16.
If the 5 th digit of user input is "1", OR | that unsigned integer with 8.
If the 6th digit of user input is "1", OR| that unsigned integer with 4.
If the 7 th digit of user input is "1", OR | that unsigned integer with 2.
If the 8th digit of user input is "1", OR| that unsigned integer with 1.
A sample algorithm to print the bits of an unsigned integer:
AND & that unsigned integer with 128. If the result is not 0, output "1". Otherwise output "0".
AND & that unsigned integer with 64. If the result is not 0, output "1". Otherwise output "0".
AND & that unsigned integer with 32. If the result is not 0, output "1". Otherwise output "0".
AND & that unsigned integer with 16. If the result is not 0, output "1". Otherwise output "0".
AND & that unsigned integer with 8. If the result is not 0, output "1". Otherwise output "0".
AND & that unsigned integer with 4. If the result is not 0, output "1". Otherwise output "0".
AND & that unsigned integer with 2. If the result is not 0, output "1". Otherwise output "0".
AND & that unsigned integer with 1. If the result is not 0, output "1". Otherwise output "0".
Run your program
Use the user input above.
Please help me write this in Python. Thank you.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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!