python.. write a program which does multiplication on binary numbers
`Hey,
Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries
Note: Brother sometimes while uploading on HomeworkLib the indentations change. So, I request you to verify once with the screenshot.
# encode int to binary list
def bn(n):
return list(reversed(list(map(lambda x: 1 if x == "1" else 0,
"{0:b}".format(n)))))
def is_zero(n):
return not n[1:] and not n[0]
def is_one(n):
return not n[1:] and n[0]
# multiplication
def multiply2(a, b):
def _(c, d, f, g, e):
if not b and not c:
return g + (e if e[1] else e[:1])
if c:
# clumsy part is the formation of A and x
A = 0 if (0 if (1 if c[0] and d else 0) == (e[1] if e else 0) else
1) == (f[0] if f else 0) else 1
# x = [0, 0] or [1, 0] or [0, 1] or [1, 1]
x = [A, 1 if ((e[1] if e else 0) or (f[0] if f else 0)) and c[0]
and d or \
((e[1] if e else 0) and (f[0] if f else 0)) and not c[0] and d else
0]
#print(x, c, d, e, f, g)
return _(c[1:], d, f[1:], (g + e[:1] if e else g), x)
return g[:1] + _(a, b.pop(0), g[1:] + e, [], [])
return [0] if is_zero(a) or is_zero(b) else \
b if is_one(a) else \
a if is_one(b) else _(a, b.pop(0), [], [], [])
print(multiply2(bn(101), bn(11)))
Kindly revert for any queries
Thanks.
python.. write a program which does multiplication on binary numbers
Multiplication of two numbers: Write a recursive program that multiplies two integers. As an input to your program perform multiplication of the largest 8-bit number (unsigned) with the largest 16-bit number (unsigned) [Programming, 10 Points]. Complete in python and show output
Write a function program in python to implement/simulate a finite automaton that accepts (only):Odd length binary numbers // 0000001, 101, 11111, etc. the program must be based on the finite automatic theory. cannot use string
PYTHON 3 PROGRAM 20.2 (Comparing performance) Write a test program that randomly generates 500000 numbers and inserts them into a BinaryTree, reshuffles the 500000 numbers and performs search, and reshuffles the numbers again before deleting them from the tree. Write another test program that does the same thing for an AVLTree. Compare the execution times of these two programs.
Question 1 - while .. else loop Write a Python program to create the multiplication table (from 1 to 12) of a number that is given by the user. Example: User keyed in number 5 Output: Multiplication Table for 5 1 x 5 = 5 2 x 5 = 10 . . . 10 x 5 = 50 11 x 5 = 55 12 x 5 = 60
In VS if you can please!! Multiplication write a program that executes the multiplication of two numbers entered by the user using only the addition operation. For example, if the user enters 3 and 4, the program computes the multiplication of these numbers by adding the number 4 three times (i.e., 3 * 4 = 4 + 4 + 4). Solve this problem in the most efficient way.
Write a python program to design a function with a parameter called A (which is between 1 and 10) and prints the multiplication table for 1 to A. • Note: Do not need to draw the horizontal and vertical lines. • Example for A = 10
In PYTHON Write a program that # 1) Creates a list of 25 numbers that are all different # 2) Takes a user-input number and then determines which number in the list is closest to the user-input number.
In C++ The Multiplication Program Step 1: Write a program that stores a multiplication table in a 9-by-9 two-dimensional array. Generate the multiplication table with two loops. (So you will have a nested loop that will iterate 9 times and fill the 9x9 array with the values.) Step 2: Display the table for the user to see it. a 9x9 table Step 3: Create a function that returns the product of two numbers between 1 and 9by looking up the...
write a python program which finds three consecutive odd numbers whose sum adds up to 45 and return a list of the numbers in ascending order do not use any other packages such as numpy or math
Perform binary multiplication using the unsigned binary numbers. Please show your work, thanks 1100 x101 -------------