Small C-Program

Can anyone tell me what is going on in this code, step by step, because when I calculate this in a paper, it should be a wrong result, but the coe is working fine, I need a step by step explanation.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  #include<stdio.h>
#include<conio.h>

int main()

{
    int d, i, pos=1, b=0;
   
	printf("Enter the binary number");
	scanf("%d",&d);             
	
	do
	
	{
	  b=b+(pos * (d%10)) ;
	   pos = pos*2;
	   
	   d = d/10;
	   
	} 
	while (d>0);
	
	printf("%d", b);
	
	
	
	getch();
   
 }

Give us an example of you stepping through the code so we can point out where you went wrong.
Topic archived. No new replies allowed.