title: Trouble converting decimal value to binary
body: <p>I'm making a program that converts decimal values to binary and vice versa. I've figured out how to convert binary to decimal, however I am having trouble with decimal to binary. I've seen many sources with code on how to do it but most of them involve using an array. I can't use an array because this program has a GUI and JLabel can't print the array. I've found a code that works with certain numbers, but doesn't with others. Here's the code:</p>
  <pre><code>public void convertBinary (int decimal)
      {
          String binary = &quot;&quot;;
          int remainder;
          
          while (decimal != 0)
          {
              remainder = decimal % 2;
              decimal /= 2;
              binary += remainder;
          }
          lblDecBinAns.setText(String.valueOf(binary));
                  
          
      }
  </code></pre>
  <p>The given number is inputted by the user (&quot;decimal&quot;) which is taken when they press the button. I don't know if there's an adjustment that can be made to this code for it to work properly. Perhaps there's an entirely different algorithm that would work for this or maybe a way to print an array with JLabel. I've been stumped on this for a while so any help is appreciated. Thanks.</p>
  <p><strong>P.S.</strong>
  I'm aware of the .toBinary function, but I must create my own method for this one.</p>