Von neuman loves binary doubt

sir my answer is coming like 101
5
1111
15
not like 101
1111
5
15
sir where i am going wrong

hello @udaycodingblocks

for(int j=0;j<=sizeof(num);j++)
		{
			int rem=num%10;
			ans=ans+(pow(2,j))*rem;
			num=num/10;

		}

here sizeof(num) will not give u the number of digit that num has.
instead it will give the space taken by num.

to fix this use while loop.

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.