title: binary to decimal in C programming
body: <p>I am trying to write a program which turns a binary number to decimal or decimal to binary. I have conditions, one of them is that I have to get numbers and number systems answers with the <code>gets</code> function. In my program, I changed char string to an integer value in order to use numbers. This is my little program.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  int i,j,m, testnumber,realnumber,indx, total,k,x[10];
  char numbersystem;
  char number[10];
  
  int main (){
      printf("Is your number \"decimal\" (d) or \"binary\" (b)) ");
      numbersystem = getchar();
      getchar();
  
      printf("Please Type your numbers");
      gets(number);
  
  i=0;
  realnumber=0;
  while(number[i]!='\0'){
      realnumber = realnumber*10 + (number[i]-48);
      i++;
  }
  
  testnumber = i;
  indx=1;
  
    if( numbersystem == 'b'){
        for(j=0; j&lt;testnumber; j++){
           if (((number[j]-48)!=0) || ((number[j]-48)!=1)) {
               printf("\nYou cannot use diffrent number in Binary form\n");
               break;
           }else {
              for(k=testnumber-1; k&gt;0; k--){
                 if((number[k]-48)=='1'){
                  for(m=0; m&lt;j; m++){
                      indx = indx*number[m];
                  }
                  total = total + indx;
              }
            }
        }
     }
       printf("Number %d\n\n",total );
    }
  }
  </code></pre>
  
  <p>My problem is I think here:</p>
  
  <pre><code>((number[j]-48)!=0) || ((number[j]-48)!=1))
  </code></pre>
  
  <p>I tried different ideas, then when I changed char string to integer, </p>
  
  <pre><code>(number[j]-48) 
  </code></pre>
  
  <p>showed me a digit.</p>
  
  <p>But when I tried to type binary numbers in my original program,  I used just "0" and "1" but I'm reaching this statement:</p>
  
  <pre><code>printf("\nYou cannot use diffrent number in Binary form\n");
               break;
  </code></pre>
  
  <p>I don't know what is the exact problem, so I need your help.</p>