// TS8802 Project by John Phillips on 6/24/2003 last revised 6/26/2003

public class BinToDec extends Problem {
  
  public BinToDec()
  {
    newProblem();
  }

  public void newProblem()
  {
    int decNum = ( int ) ( Math.random() * 127 );
    String binNum = Integer.toString( decNum, 2 );
    setAnswer( Integer.toString( decNum ) );
    setQuestion( "Use pencil and paper to solve the following problem:\n\n" + 
      "Convert the binary number " + binNum + " to decimal." );
  }

  public String hint()
  {
    return "To convert a binary number to a decimal number start with the rightmost bit. " +
           "That bit is in the 1's column. The next bit to the left is in the 2's column. " +
           "The 3rd bit to the left is in the 4's column. Next is the 8's column, the 16's column, " +
           "and so on, doubling each time. For each column, if the bit is a 1 then add the " +
           "column weighting onto the total. If a bit is a zero then ignore it. " +
           "The number 101 has a one bit in the 1's column, a zero bit in the 2's column, " +
           "and a 1 bit in the 4's column. So adding the column weightings gives us 4 + 1 or 5. " +
           "Therefore, 101 binary is 5 decimal.";
  }
}