PDA

View Full Version : Need to calculate checksum, how can I do it?



Zizione
23rd January 2018, 16:53
Hellow guys,
I am doing a programm using QT. I have a intelHex file(.mcs) which stores bunch of lines with Hex type data. For now my programm reads 1st line of the file, parsing(if i correct) this and store into an QbyteArray object.
For example 1st line of the file is :":020000040010EA" and after compilation in my QbyteArray object i have this :"\x02\x00\x00\x04\x00\x10\xEA".
What my teacher said thats right. Now I need to calculet checksum for this bytes and send a message.
If it would help to understand what i need there is a python code what I am trying to do


if (sum(bytes) & 0xFF) != 0:
print('Bad checksum!')
raise StopIteration

high_flyer
28th January 2018, 12:41
f it would help to understand what i need
And it would help if you explained what the actual question is.
is the sum() function in your code implemented or do you need to implement it and don't know how?
If it is implemented - I don't understand what you need.
If you can explain a bit more about the problem you have it wold help us to help you.
If the problem is how to implement a checksum, google and wikipedia are a good place to start there is a lot information available on the internet about checksum calculation, and various types of checksum algorithms.
You can ask here any specific questions you need help with if you are stuck.