Results 1 to 18 of 18

Thread: QByteArray sum

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #14
    Join Date
    Apr 2017
    Posts
    10
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: QByteArray sum

    OK I'll try one more time...
    I do not care about right human meaning of sum of elements I have in dynamical array. That array is received by seial port bytes.
    parsing that package I need to be sure received bytes are sent from one device. In my case sender device can send other information it received from other ports. In that case bytes could pass true directly to parser. To be sure package is OK I need to check sum. Chance it happen is very small that why I decided to count bytes as insurance it is save to parse it. Not checksum working same way by the way.
    Next---> it is easy to just count array[1]+ array[2] +arr.... and send that info.
    In my case is lack of memory says me to save even byte... so that sum I want store in BYTE not LONG lot VERY LONG not any other just unsigned byte.
    Math says to me that byte would be same:
    1+10+215+35+60 = 321 - 256 = 65
    256 is byte -------> 0 to 255 is 256 man!!!!
    so if u'll count bytes 255+255+255+255+255 it will be in byte 251 not sure but... must be
    so the best C++ way, I've found, to do so is:
    bytearray[0] = bytearray[0] + sp_ar_dataToSend[i]
    to your attention not bytearray[0] += sp_ar_dataToSend[i] initialization will return wrong val.
    I am sure it is not good to initialize other, byte array variable to count one byte.
    You can try to use char and if it will work, or you'll find other variable remind me.
    sum % 256 might be ok but:
    I am sure it is not good to initialize other, byte array variable to count one byte.
    same as long float and other.
    But to use LONG and than count % is absolutely wrong way, same as
    Qt Code:
    1. int sum += sp_ar_dataToSend[i]
    2. for (int i = sum; i > 256;) {
    3. sum-=256;
    4. i=sum;
    5. }
    6. data.append((const char*)(&sum), sizeof(int));
    To copy to clipboard, switch view to plain text mode 

    Last edited by FalloutST; 4th April 2017 at 14:07.

Similar Threads

  1. Replies: 6
    Last Post: 14th May 2014, 12:14
  2. Replies: 1
    Last Post: 22nd June 2011, 08:12
  3. Regarding qbytearray
    By mohanakrishnan in forum Qt Programming
    Replies: 7
    Last Post: 19th November 2009, 13:38
  4. Replies: 9
    Last Post: 25th July 2009, 13:27
  5. QByteArray in Qt3
    By joseph in forum Qt Programming
    Replies: 1
    Last Post: 6th September 2007, 06:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.