VOOZH about

URL: https://www.geeksforgeeks.org/dsa/multiply-two-numbers-of-different-base-and-represent-product-in-another-given-base/

⇱ Multiply two numbers of different base and represent product in another given base - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Multiply two numbers of different base and represent product in another given base

Last Updated : 23 Jul, 2025

Given two numbers N, M in the bases X, Y and another base P. The task is to find the product of N and M and represent the product in base P.

Examples:

Input: N = 101, M = 110, X = 2, Y = 2, P = 16
Output:1E
Explanation: NX * MY =  (101)2 * (110) = (11110)2
(11110)2 = (1E)16

Input:  N = 101, M = A, X = 2, Y = 20, P = 16
Output:  32
Explanation: Nx = (101)2 = (5)20  
NX  *  MY =  (5)20 * (A)20  = (2A)20
(2A)20 = (32)16

Approach: The approach is to convert the given numbers in decimal, perform the product and then turn it back to a number of base p. Follow the steps mentioned below:

  1. Convert NX and MY to decimal number.
  2. Perform multiplication on the decimal numbers.
  3. Convert the result of multiplication from decimal to base P.

Below is the implementation of the above approach. 

 
 


Output
1E


 

Time Complexity: O(D) where D is the maximum number of digits in N, M and product
Auxiliary Space: O(1)


 

Comment