Question

[PYTHON] 15.7.1: Bitwise Operations on Bit Strings

[PYTHON]

 Complete the definitions for the bitwise_and, bitwise_or, and bitwise_xor functions. Each function should accept two bit strings of equal length and output a single binary string of the same length.

 15.7.1: Bitwise Operations on Bit Strings (Difficulty: III)

OBJECTIVE Complete the definitions for the bitwise_and, bitwise_or, and bitwise_xor functions. Each function should accept tw

2 0
Add a comment Improve this question Transcribed image text
Answer #1

def bitwise_and(p, q):
c = p & q # bitwise and
return c

def bitwise_or(p, q):
c = p|q # bitwise or
return c

def bitwise_xor(p, q):
c = p ^ q # bitwise xor
return c

/* PLEASE UPVOTE (THANK YOU IN ADVANCE) IF ANY QUERY ASK ME IN COMMENT SECTION I WILL RE-SOLVE THE QUESTION FOR YOU */

Add a comment
Know the answer?
Add Answer to:
[PYTHON] 15.7.1: Bitwise Operations on Bit Strings
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • language is python Write a function named subsetStrings that has two inputs, a list of strings...

    language is python Write a function named subsetStrings that has two inputs, a list of strings and an integer n. Your function should use a single list comprehension to create a new list containing the first n characters of each string in the input list if the length of the individual string is at least n (strings that are too short should be skipped). Your function should return the new list ex: inputList 'Frederic, 'powerade', 'spring break, 'pen'] and n-4...

  • In python please. Write a program that reads whitespace delimited strings (words) and an integer (freq)....

    In python please. Write a program that reads whitespace delimited strings (words) and an integer (freq). Then, the program outputs the strings from words that have a frequency equal to freq in a case insensitive manner. Your specific task is to write a function wordsOfFreqency(words, freq), which will return a list of strings (in the order in which they appear in the original list) that have a frequency same as the function parameter freq. The parameter words to the function...

  • Language is Python Question 1: Octoquadragesimal Conversion (6 points) There are many exotic base systems in...

    Language is Python Question 1: Octoquadragesimal Conversion (6 points) There are many exotic base systems in the world, one of which is Octoquadragesimal, which is based on the number 48. The Octoquadragesimal digits are as follows: 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g, h,i,j,k,1,m,n,o,p,q,r.s,t,u,v,w.x,y,z,A,B,C,D,E,F,G,H,1,J,KL Write two functions, Octoquadragesimal2Binary(x) and Binary2Octoquadragesimal(x), which convert from Octoquadragesimal to Binary, and from Binary to Octoquadragesimal respectively. The input x is a string in both cases, and the outputs of these functions should be strings of binary or octoquadragesimal numbers respectively....

  • PYTHON The text file motifFinding.txt contains two strings of DNA code, separated by a new-line character....

    PYTHON The text file motifFinding.txt contains two strings of DNA code, separated by a new-line character. Write a program that opens the file, and stores its contents into two strings, s and t, respectively.   Write code that will find all instances of the string t within the string s. At the end, your program should output the number of times the sub-string t occurs within s, along with the index of the starting position of each occurrence of t within...

  • Programming Exercise 4.6 Use the strategy of the decimal to binary conversion and the bit shift...

    Programming Exercise 4.6 Use the strategy of the decimal to binary conversion and the bit shift left operation defined in Project 5 bits = input("Enter bit string: ") bits = bits[1:] + bits[0] print ("Result:", bits) to code a new encryption algorithm. The algorithm should Add 1 to each character’s numeric ASCII value. Convert it to a bit string. Shift the bits of this string one place to the left. A single-space character in the encrypted string separates the resulting...

  • Computer science Implement these below questions in C++: 1. Given two-bit strings of length n, find...

    Computer science Implement these below questions in C++: 1. Given two-bit strings of length n, find the bitwise AND, bitwise OR, and bitwise XOR of these strings. 2. Looking for positive integers that are not the sum of the cubes of nine different positive integers. 3. Given subsets A and B of a set with n elements, use bit strings to find A, A ∪ B, A ∩ B, A − B, and A ⊕ B. 4. Given a finite...

  • In pyhton 3.7 please 2. Write a function that takes, as an argument, either a 12-digit...

    In pyhton 3.7 please 2. Write a function that takes, as an argument, either a 12-digit positive integer n or a string consisting of 12 digits, and calculates the 13th digit (the check digit) for a 13-digit ISBN. Name this function calculateCheckDigit(n). For example, >>>calculateCheckDigit(452678904653) should return 5. As an additional example, >>>calculateCheckDigit(546654945486) should return 8. 3. Write a function that takes, as an argument, an eight-bit binary string and does the following, in this order: • Verifies that it...

  • How many bit strings of length n are palindromes

    How many bit strings of length n are palindromes? Hint: Consider two cases n is even and n is odd. Note a palindrome is a “string” of letters or numbers which read the same “frontwards” and backwards”. Examples: 1101011, 10111101 are palindromes.

  • Python code Write a program that will ask the user to input two strings, assign the...

    Python code Write a program that will ask the user to input two strings, assign the strings to variables m and n If the first or second string is less than 10 characters, the program must output a warning message that the string is too short The program must join the strings m and n with the join function The output must be displayed. Please name the program and provide at least one code comment (10)

  • PYTHON The function longest that returns the longest of two strings. The function count_over that takes...

    PYTHON The function longest that returns the longest of two strings. The function count_over that takes a list of numbers and an integer nand returns the count of the numbers that are over n. The function bmi that takes two parameters height and weight and returns the value of the body mass index: a person's weight in kg divided by the square of their height in meters. def longest(string1, string2): """Return the longest string from the two arguments, if the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT