Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QByteArray sum element and Converting into integer

QByteArray sum element and Converting into integer

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.3k Views 2 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.
  • N Offline
    N Offline
    Nopa11
    wrote on last edited by
    #1

    Hi, I'm new beginner in Qt. I'm using QbyteArray to read int 2 byte data from Serialport. I need to sum element
    such as Serialport sent { 0xff, 0x0f } and QbyteArray data received { data[0] = 0xff , data[1] = 0x0f }
    I need to data[1] brfore data[0] ( 0000 1111 , 1111 1111) --> to sum --> (0000 1111 + 1111 1111) = ( 0000 1111 1111 1111)
    and converting to integer.

    coding

    QByteArray data = serial.readAll();

    int num = data[0].prepend(data[1]);

    ui->lcdnumber->display(num);

    but it's doesn't work. Thanks

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by A Former User
      #2

      Hi,
      generally speaking, you need to take a look at bitwise operations in C++. Your problem boils down to:

      quint8 a = 0xff;
      quint8 b = 0x0f;
      quint16 result = (quint16)b<<8 | (quint16)a;
      

      Hope this helps!

      1 Reply Last reply
      0
      • N Offline
        N Offline
        Nopa11
        wrote on last edited by
        #3

        It's work. Thank you so much

        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