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:
256 is byte -------> 0 to 255 is 256 man!!!!1+10+215+35+60 = 321 - 256 = 65
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:
same as long float and other.I am sure it is not good to initialize other, byte array variable to count one byte.
But to use LONG and than count % is absolutely wrong way, same as
Qt Code:
int sum += sp_ar_dataToSend[i] for (int i = sum; i > 256;) { sum-=256; i=sum; } data.append((const char*)(&sum), sizeof(int));To copy to clipboard, switch view to plain text mode
Bookmarks