please let me know where is my code failing
Coversion Any to Any
your are not considering all combinations
you can do it like this
if(sb==2){
if(db == 8){
// binary to Ocatal
}else if(db == 10){
// binary to Decimal
}else if(db == 16){
// binary to Hexal
}
}else if(sb == 8){
if(db == 2){
// Ocatal to Binary
}else if(db == 10){
// Ocatal to Decimal
}else if(db == 16){
// Ocatal to Hexal
}
}else if(sb == 16){
if(db == 2){
// Hexal to Binary
}else if(db == 10){
// Hexal to Decimal
}else if(db == 8){
// Hexal to Ocatal
}
}
but this will be not a better approach
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.
Reference Code
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.