hi

I made an application witch converts binary numbers into decimal numbers and back. It is not hard to write and it is not hard to understand.
If you want my code, just send me an e-mail ;)

First I created a form like this:
binary

Then I created two private slot functions (“in the .h file” you can also define it as a private function or public (slots) function, in this case, it doesn’t matter what you choose)

void convertToBinary(int number);
void convertToDecimal();

in the button “Dec to Bin” I write (“in the .cpp file”)

convertToBinary(ui->decimalEdit->text().toInt());

in the button “Bin to Dec” I write

convertToDecimal();

NOTE: you also can write the full code into the buttons self, but if you are making bigger projects (300 rows + ) it is quite useful you define them as a function.

you write into the “convertToBinary” function

QString output;
do
{
  output.prepend(QString::number(number % 2));
  number /= 2;
} while (number <= 1);
ui->binaryEdit->setText(output);

into the “convertToDecimal” function you type

int zero = 0;
int one = 1;
for (int i = ui->binaryEdit->text().length() - 1; i >= 0;--i) {
  if (!ui->binaryEdit->text()[i].isNumber()) {
    ui->decimalEdit->setText("ERR");
    return;
  }
  if (ui->binaryEdit->text()[i] == '1') {
    zero += one;
  }
  one = one *2;
}
ui->decimalEdit->setText(QString::number(zero));

If you need help, just write a comment or write me a mai (you can find it in on the “Contact” page)