Python Program to Multiply Two Binary Numbers Last Updated : 23 Feb, 2023 Comments Improve Suggest changes Like Article Like Report Given two binary numbers, and the task is to write a Python program to multiply both numbers. Example: firstnumber = 110 secondnumber = 10 Multiplication Result = 1100 We can multiply two binary numbers in two ways using python, and these are: Using bin() functions andWithout using pre-defined functionsMethod 1: Using bin Functions Now, Let's write a program by using Pre-Defined Functions: Python3 firstnumber = 110 secondnumber = 10 firstnumber = str(firstnumber) secondnumber = str(secondnumber) Multiplication = int(firstnumber, 2) * int(secondnumber, 2) binaryMul = bin(Multiplication) print("\nResult = " + binaryMul) Output: Result = 0b1100 Time complexity: O(1) Auxiliary space: O(1) Method 2: Without using Any Pre-Defined Function We can also multiply any two Binary Numbers without using any pre-defined Function or by user-defined function. Python def binaryProduct(binaryOne, binaryTwo): i = 0 remainder = 0 sum = [] binaryProd = 0 # if firstBinary number or second Binary number is not # zero then calculate the product of two Binary numbers while binaryOne != 0 or binaryTwo != 0: sum.insert(i, (((binaryOne % 10) + (binaryTwo % 10) + remainder) % 2)) remainder = int(((binaryOne % 10) + (binaryTwo % 10) + remainder) / 2) binaryOne = int(binaryOne/10) binaryTwo = int(binaryTwo/10) i = i+1 # if remainder value is not equal to # zero then insert the digit to sum array if remainder != 0: sum.insert(i, remainder) i = i+1 i = i-1 while i >= 0: binaryProd = (binaryProd * 10) + sum[i] i = i-1 return binaryProd binaryMultiply = 0 factor = 1 firstBinary = 110 secondBinary = 10 # Now check if secondbinary number have any # digit or not and continue multiplying # each digit of the second binary number with # first binary number till the last digit of # second binary number while secondBinary != 0: digit = secondBinary % 10 if digit == 1: firstBinary = firstBinary * factor binaryMultiply = binaryProduct(firstBinary, binaryMultiply) else: firstBinary = firstBinary * factor secondBinary = int(secondBinary/10) factor = 10 print("\nMultiplication Result = " + str(binaryMultiply)) Output: Multiplication Result = 1100 Time complexity: O(n), where n is the length of the binary numbers. Auxiliary space: O(n), as we are storing the binary product in the sum array. Python3 from operator import* num1="110" num2="10" print(bin(mul(int(num1,2),int(num2,2)))) Output 0b1100 Comment More infoAdvertise with us Next Article Python Program to Multiply Two Binary Numbers A AnujMehla Follow Improve Article Tags : Python Python Programs school-programming Practice Tags : python Similar Reads Python program to add two binary numbers Given two binary numbers, write a Python program to compute their sum. Examples: Input: a = "11", b = "1" Output: "100" Input: a = "1101", b = "100" Output: 10001Approach: Naive Approach: The idea is to start from the last characters of two strings and compute digit sum one by one. If the sum become 4 min read Python Program to Subtract Two Binary Numbers We are given two binary numbers, num1 and num2 and we have to subtract these two binary numbers and return the result. In this article, we will see how we can subtract two binary numbers in Python.Examples:Input: a = "1110" , b = "0110"Output: "1000"Explanation: We can see that when "1110" is subtra 3 min read Python Program to Multiply Two Matrices Given two matrices, we will have to create a program to multiply two matrices in Python. Example: Python Matrix Multiplication of Two-DimensionPythonmatrix_a = [[1, 2], [3, 4]] matrix_b = [[5, 6], [7, 8]] result = [[0, 0], [0, 0]] for i in range(2): for j in range(2): result[i][j] = (matrix_a[i][0] 5 min read Python Program To Multiply Two Numbers Represented By Linked Lists Given two numbers represented by linked lists, write a function that returns the multiplication of these two linked lists. Examples: Input: 9->4->6 8->4Output: 79464Input: 3->2->1 1->2Output: 3852Recommended: Please solve it on "PRACTICE" first, before moving on to the solution.Pyt 3 min read Python Program to add two hexadecimal numbers Given two hexadecimal numbers, write a Python program to compute their sum. Examples: Input: a = "01B", b = "378" Output: 393 Explanation: B (11 in decimal) + 8 = 19 (13 in hex), hence addition bit = 3, carry = 1 1 + 7 + 1 (carry) = 9, hence addition bit = 9, carry = 0 0 + 3 + 0 (carry) = 3, hence a 6 min read Python program to add two Octal numbers Given two octal numbers, the task is to write a Python program to compute their sum. Examples: Input: a = "123", b = "456" Output: 601 Input: a = "654", b = "321" Output: 1175Approach: To add two octal values in python we will first convert them into decimal values then add them and then finally aga 2 min read Python Program to Find the Gcd of Two Numbers The task of finding the GCD (Greatest Common Divisor) of two numbers in Python involves determining the largest number that divides both input values without leaving a remainder. For example, if a = 60 and b = 48, the GCD is 12, as 12 is the largest number that divides both 60 and 48 evenly. Using e 2 min read Python program to convert ASCII to Binary We are having a string s="Hello" we need to convert the string to its ASCII then convert the ASCII to Binary representation so that the output becomes : 01001000 01100101 01101100 01101100 0110111. To convert an ASCII string to binary we use ord() to get the ASCII value of each character and format( 2 min read Python program to convert Base 4 system to binary number Given a base 4 number N, the task is to write a python program to print its binary equivalent. Conversion Table: Examples: Input : N=11002233 Output : 101000010101111 Explanation : From that conversion table we changed 1 to 01, 2 to 10 ,3 to 11 ,0 to 00.Input : N=321321 Output: 111001111001Method 1: 3 min read Python3 Program to Rotate bits of a number Bit Rotation: A rotation (or circular shift) is an operation similar to a shift except that the bits that fall off at one end are put back to the other end. In the left rotation, the bits that fall off at the left end are put back at the right end. In the right rotation, the bits that fall off at th 3 min read Like