title: C++ Binary to decimal?
body: <p>I made a function that converts binary numbers to decimals, but if i go to high on the binary numbers, it just returns 256??? What could cause this? I'm using int variables. Any help would be really appreciated</p>
  
  <pre><code>    #include &lt;iostream&gt;
  
  using namespace std;
  
  int FromBin (int n)
  {
      int increment;
      int Result;
      increment = 1;
      Result = 0;
      while(n != 0)
      {
          if (n % 10 == 1){
              Result = Result+increment;
              n = n-1;
          }
          n = n/10;
          increment = increment*2;
      }
      cout&lt;&lt;Result;
  }
  
  void ToBin(int n)
  {
      if (n / 2 != 0) {
          ToBin(n / 2);
      }
      cout&lt;&lt;n % 2;
  }
  
  int main()
  {
      int choice;
      int n;
      cout&lt;&lt;"Choose a function: press 0 for decimals to binary, press 1 for binary to decimal\n";
      cin&gt;&gt;choice;
      if (choice == 0){
          cout&lt;&lt;"Enter a number: \n";
          cin&gt;&gt;n;
          ToBin(n);
      }
      else if (choice == 1){
          cout&lt;&lt;"Enter a number: \n";
          cin&gt;&gt;n;
          FromBin(n);
      }
      else{
          cout&lt;&lt;"Invalid input";
      }
  }
  </code></pre>
  
  <p>I'm new to C++ so I don't understand this... :/</p>