title: Reversal of a binary number with strings
body: <p>My code isn't working. It is the initial part of my program. The main error occurs when I try to reverse the string. Can someone look at it?</p>
  
  <p>I have to get the string reversed in order to convert the binary number into a decimal.</p>
  
  <pre><code>  String checka, checkb;
    checka = txt1.getText();
    checkb = txt2.getText();
    int lchecka = checka.length();
    int lcheckb = checkb.length();
    int ia, ib, p = 1, q = 1;
  
    for (ia = 0; ia &lt; lchecka; ia++)
    {
       if (checka.charAt(ia) == '1' || checka.charAt(ia) == '0')
       {
          p = 1;
       }
       else
       {
          p = 0;
          break;
       }
    }
    for (ib = 0; ib &lt; lcheckb; ib++)
    {
       if (checkb.charAt(ib) == '1' || checkb.charAt(ib) == '0')
       {
          q = 1;
       }
       else
       {
          q = 0;
          break;
       }
    }
  
    double adda = 0, addb = 0, ansa = 0, ansb = 0;
    int inta, intb;
    inta = Integer.parseInt(txt1.getText());
    intb = Integer.parseInt(txt2.getText());
    if (p == 1 &amp;&amp; q == 1)
    {
       String checkka;
       checkka = txt1.getText();
       String checkkb;
       checkkb = txt2.getText();
       int lcheckka = checkka.length();
       int lcheckkb = checkkb.length();
       Character oa, ob;
  
       int ra, rb;
       String reva, revb;
       oa = checkka.charAt(lcheckka - 1);
       reva = oa + "";
       ob = checkkb.charAt(lcheckkb - 1);
       revb = ob + "";
  
       oa = checkka.charAt(lcheckka - 2);
       reva = reva.substring(0) + oa;
       ob = checkkb.charAt(lcheckkb - 2);
       revb = revb.substring(0) + ob;
  
       for (ra = lcheckka - 3; ra &gt;= 0; ra--)
       {
  
          oa = checkka.charAt(ra);
          reva = reva.substring(0, ra - 1) + oa;
       }
       for (rb = lcheckkb - 3; rb &gt;= 0; rb--)
       {
  
          ob = checkkb.charAt(rb);
          revb = revb.substring(0, rb - 1) + ob;
       }
  
       System.out.println(reva);
       System.out.println(revb);
    }
  </code></pre>