can someone tell what the question is asking and what should be the approach
Conversion any to any
hi @akshat42bajpai
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 conver 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;
}
yes it’s clear for now
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.