Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. German
  4. Binary TO Decimal
Forum Updated to NodeBB v4.3 + New Features

Binary TO Decimal

Scheduled Pinned Locked Moved Unsolved German
7 Posts 4 Posters 871 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    M.W43
    wrote on last edited by
    #1

    Hallo,
    ich versuche über ein LineEdit ein Binärmuster einzulesen und über eine LCDNumber auszugeben.
    Allerdings wird mir aus einen binäre Wert 0101 dezimal der Wert 10 ausgeben, was ja bekanntlich Flasch ist. Die Bit Reihenfolge ist gedreht, das niederwertige Bit ist nicht mehr rechts sondern links.

    Ich weiß nicht wie ich es drehen kann?

    void Dialog::on_pushButton_2_clicked()
    {
        
        //ui->lineEdit->setAlignment(Qt::AlignRight);
        //ui->lineEdit->setLayoutDirection(Qt::RightToLeft);
        
        
        QString bin;
        double ausgabe = 0;
        bin = ui->lineEdit->text();
        int end = bin.size();
        
        
        for(int i = 0; i != end; ++i)
        {
            QString c = bin[i];
            if (c == '1' || c == '0'){
                if (c == '1')
                    ausgabe += pow(2, i);
            }
        }
        
        ui->lcdNumber->display(ausgabe);
    }
    
    
    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by Christian Ehrlicher
      #2

      Einfach die for-Schleife rückwärts ausführen. Also bei size() - 1 anfangen und auf 0 runter zählen.
      Sorry - natürlich dann auch anstatt pow(2, i) pow (2, size() - i - 1)

        for(int i = 0; i < bin.size(); ++i)
        {
            QChar c = bin[i];
            if (c == '1')
              ausgabe += pow(2, bin.size() - i - 1);
        }
      

      Oder am einfachsten: QString::toInt()

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      JonBJ 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        Einfach die for-Schleife rückwärts ausführen. Also bei size() - 1 anfangen und auf 0 runter zählen.
        Sorry - natürlich dann auch anstatt pow(2, i) pow (2, size() - i - 1)

          for(int i = 0; i < bin.size(); ++i)
          {
              QChar c = bin[i];
              if (c == '1')
                ausgabe += pow(2, bin.size() - i - 1);
          }
        

        Oder am einfachsten: QString::toInt()

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @Christian-Ehrlicher said in Binary TO Decimal:

        Sorry

        Ist "Sorry" jetzt ein Deutsches Wort? :)

        Pl45m4P 1 Reply Last reply
        0
        • M Offline
          M Offline
          M.W43
          wrote on last edited by
          #4

          Ich bedanke mich bei euch und wünsche einen gute Rutsch ins neue Jahr.

          1 Reply Last reply
          0
          • JonBJ JonB

            @Christian-Ehrlicher said in Binary TO Decimal:

            Sorry

            Ist "Sorry" jetzt ein Deutsches Wort? :)

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by
            #5

            @JonB

            Ist Kindergarten ein englisches Wort?! :)

            Some English words are commonly used in German, esp. on the Internet or in chats / messengers etc.


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            JonBJ 1 Reply Last reply
            1
            • Pl45m4P Pl45m4

              @JonB

              Ist Kindergarten ein englisches Wort?! :)

              Some English words are commonly used in German, esp. on the Internet or in chats / messengers etc.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @Pl45m4
              Yes, kindergarten is a perfectly English word :)
              When I was at school and learned German there was no "Sorry". Nor did Kafka/Goethe ever use it.
              Internet chat has a lot to answer for!

              Frohes Neues Jahr!!

              Pl45m4P 1 Reply Last reply
              0
              • JonBJ JonB

                @Pl45m4
                Yes, kindergarten is a perfectly English word :)
                When I was at school and learned German there was no "Sorry". Nor did Kafka/Goethe ever use it.
                Internet chat has a lot to answer for!

                Frohes Neues Jahr!!

                Pl45m4P Offline
                Pl45m4P Offline
                Pl45m4
                wrote on last edited by
                #7

                @JonB

                Back in Goethe times the German language was a lot different. I would say, comparable to Shakespeare vs. the English, the younger generation speaks nowadays.


                If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                ~E. W. Dijkstra

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved