Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. ADDENDUM How to display full 4 binary bits - after QString "number" option converts string to int. including hexadecimal strings.

ADDENDUM How to display full 4 binary bits - after QString "number" option converts string to int. including hexadecimal strings.

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestionc++database
3 Posts 2 Posters 5 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.
  • J Offline
    J Offline
    jana_hus
    wrote on last edited by
    #1

    Addendum I have settled on the following ( the example is for converting MSB ) , still convoluted ,code. I would like to find out , discuss , the usage of "toLongLong" .

           QString binaryNumber = QString::number(hexadecimalNumber.toLongLong(&ok, 16), 2).rightJustified(4,'0').leftJustified(8,'0');
    

    Up front I am very sorry to reopen this post. For information, I am leaving the original post (code). I have an additions issue, I need help with to correct. This code snippet correctly converts string "42" to binary code "01000000". I do not need more help with that conversion, BUT in need help converting when the string contains hexadecimal value, such as "F9". Changing "toInt(),2)" options to toInt(),16) does not do the job. I realize that the Qt code is little convoluted and for this reason - May I suggest that only coders with experience of Qt take a look at this ? No, it is not an instruction how to reply, just a suggestion.

                        pFT857\_library->CAT\_Data\_String\[CAT\_Data\_Index\].mid(0,1).number(pFT857\_library->CAT\_Data\_String\[CAT\_Data\_Index\].mid(0,1).toInt(),2).leftJustified(7,'0');
    

    Solution : pFT857_library->CAT_Data_String[CAT_Data_Index].mid(0,1).number(n,2).rightJustified(4,'0'); Output : " convert LSB to binary with leading zeroes " "0001"

    I have Qt style string QString frequency = "1426000" split into another QString as
    QString frequency_array = "01 42 60 00"
    I need to change each pair as 8 bit binary with
    MSD as upper 4 bits of the 8 bit word
    AND
    LSD as lower 4 bits of the 8 bit word

    For debugging purpose I like to print each step of the conversion.

    As an example , I like to see "42 "
    as
    "01000010"

    I prefer Qt QString in C++ code

    Here is my code so far

    ```
    for (int index = 0; index <6 ; index++)
    {
    text = pFT857_library->CAT_Data_String[index];
    m_ui->lineEdit_14->setText(text);
    qDebug() << text;
    text = text.mid(0,1).toLocal8Bit();
    qDebug() << text;

    text = pFT857\_library->CAT\_Data\_String\[index\];
    text = text.mid(1,1).toLocal8Bit();
    qDebug() << text;
    
    }
    

    ```

    The above WAS my initial post / code and I have dropped the post. My current code is little over-documented so I am hesitant to post it. However, I have a (simple_) question. Using the following snippet

    L 2 Replies Last reply
    0
    • J jana_hus

      Addendum I have settled on the following ( the example is for converting MSB ) , still convoluted ,code. I would like to find out , discuss , the usage of "toLongLong" .

             QString binaryNumber = QString::number(hexadecimalNumber.toLongLong(&ok, 16), 2).rightJustified(4,'0').leftJustified(8,'0');
      

      Up front I am very sorry to reopen this post. For information, I am leaving the original post (code). I have an additions issue, I need help with to correct. This code snippet correctly converts string "42" to binary code "01000000". I do not need more help with that conversion, BUT in need help converting when the string contains hexadecimal value, such as "F9". Changing "toInt(),2)" options to toInt(),16) does not do the job. I realize that the Qt code is little convoluted and for this reason - May I suggest that only coders with experience of Qt take a look at this ? No, it is not an instruction how to reply, just a suggestion.

                          pFT857\_library->CAT\_Data\_String\[CAT\_Data\_Index\].mid(0,1).number(pFT857\_library->CAT\_Data\_String\[CAT\_Data\_Index\].mid(0,1).toInt(),2).leftJustified(7,'0');
      

      Solution : pFT857_library->CAT_Data_String[CAT_Data_Index].mid(0,1).number(n,2).rightJustified(4,'0'); Output : " convert LSB to binary with leading zeroes " "0001"

      I have Qt style string QString frequency = "1426000" split into another QString as
      QString frequency_array = "01 42 60 00"
      I need to change each pair as 8 bit binary with
      MSD as upper 4 bits of the 8 bit word
      AND
      LSD as lower 4 bits of the 8 bit word

      For debugging purpose I like to print each step of the conversion.

      As an example , I like to see "42 "
      as
      "01000010"

      I prefer Qt QString in C++ code

      Here is my code so far

      ```
      for (int index = 0; index <6 ; index++)
      {
      text = pFT857_library->CAT_Data_String[index];
      m_ui->lineEdit_14->setText(text);
      qDebug() << text;
      text = text.mid(0,1).toLocal8Bit();
      qDebug() << text;

      text = pFT857\_library->CAT\_Data\_String\[index\];
      text = text.mid(1,1).toLocal8Bit();
      qDebug() << text;
      
      }
      

      ```

      The above WAS my initial post / code and I have dropped the post. My current code is little over-documented so I am hesitant to post it. However, I have a (simple_) question. Using the following snippet

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      What is pFT857_library, as that appears to be the code you are using? But if you want a simple method then you could easily write a short loop that prints the value of each of the 4 or 8 bits one by one.

      1 Reply Last reply
      0
      • J jana_hus

        Addendum I have settled on the following ( the example is for converting MSB ) , still convoluted ,code. I would like to find out , discuss , the usage of "toLongLong" .

               QString binaryNumber = QString::number(hexadecimalNumber.toLongLong(&ok, 16), 2).rightJustified(4,'0').leftJustified(8,'0');
        

        Up front I am very sorry to reopen this post. For information, I am leaving the original post (code). I have an additions issue, I need help with to correct. This code snippet correctly converts string "42" to binary code "01000000". I do not need more help with that conversion, BUT in need help converting when the string contains hexadecimal value, such as "F9". Changing "toInt(),2)" options to toInt(),16) does not do the job. I realize that the Qt code is little convoluted and for this reason - May I suggest that only coders with experience of Qt take a look at this ? No, it is not an instruction how to reply, just a suggestion.

                            pFT857\_library->CAT\_Data\_String\[CAT\_Data\_Index\].mid(0,1).number(pFT857\_library->CAT\_Data\_String\[CAT\_Data\_Index\].mid(0,1).toInt(),2).leftJustified(7,'0');
        

        Solution : pFT857_library->CAT_Data_String[CAT_Data_Index].mid(0,1).number(n,2).rightJustified(4,'0'); Output : " convert LSB to binary with leading zeroes " "0001"

        I have Qt style string QString frequency = "1426000" split into another QString as
        QString frequency_array = "01 42 60 00"
        I need to change each pair as 8 bit binary with
        MSD as upper 4 bits of the 8 bit word
        AND
        LSD as lower 4 bits of the 8 bit word

        For debugging purpose I like to print each step of the conversion.

        As an example , I like to see "42 "
        as
        "01000010"

        I prefer Qt QString in C++ code

        Here is my code so far

        ```
        for (int index = 0; index <6 ; index++)
        {
        text = pFT857_library->CAT_Data_String[index];
        m_ui->lineEdit_14->setText(text);
        qDebug() << text;
        text = text.mid(0,1).toLocal8Bit();
        qDebug() << text;

        text = pFT857\_library->CAT\_Data\_String\[index\];
        text = text.mid(1,1).toLocal8Bit();
        qDebug() << text;
        
        }
        

        ```

        The above WAS my initial post / code and I have dropped the post. My current code is little over-documented so I am hesitant to post it. However, I have a (simple_) question. Using the following snippet

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        This is a Qt issue as far as using the toInt function. And as the documentation (QString Class | Qt Core 5.15.17[^]) clearly shows, it handles numbers in any base from 2 to 36.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups