This problem is based on the concept of different number systems (binary, decimal, octal, hexadecimal, or in any other base…)
The Logic is to First convert the corresponding given source base to decimal and then convert the decimal base to Given destination base.
In short the Question is Any Base to Decimal and then Decimal to Any Base.
u can refer this -->
int conversion(int num, int sb, int db){
// Any Base to Decimal
int ans = 0;
int mult = 1;
while(num != 0){
int rem = num % 10;
ans = ans + rem * mult;
mult = mult * sb;
num = num / 10;
}
// Refresing the variables
mult = 1;
num = ans;
ans = 0;
//Decimal to Any number
while(num != 0){
int rem = num % db;
ans = ans + rem * mult;
mult = mult * 10;
num = num / db;
}
return ans;
}