Please have a look at my code . It is not passing the first and fourth test case . Also , do suggest if you have a better approach.
Link :https://ide.codingblocks.com/s/84043
Octal to Binary Daily Code Byte
So, in this case, to convert the octal number to decimal number.
Then, Convert the decimal number to binary.
int multiplier=1;
int ans=0;
int dec=0;
while(n!=0){ // Convert octal to decimal
int rem=n%10;
dec=dec+rem*multiplier;
multiplier*=8;
n=n/10;
}
multiplier=1;
while(dec!=0){ // convert decimal to binary
int rem=dec%2;
ans=ans+rem*multiplier;
multiplier*=10;
dec=dec/2;
}
return ans;
what is wrong in my 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.