In my communication protocl application a want to use a modulus 128 operation which is as follows
I have a variable 'sequence_no' which comes from communication packet.
I have to verify in my function whether the 'sequence_no' is previously received or not.
For this operation here is an algorithm
unsigned char current_no; // This my applications global variable
// packet is already received
else if( sequence_no >= current_no)
// receive packet
current_no %= 128; // I have to round off to '0' when number equals 128
// invalid packet(misalignment)
The above works fine for 0-127
My problem is, when the 'sequence_no = 127' if i receive the same packet twice for the first time it validates TRUE,
but for the second time the current_no rounds off to '0' and the condition "sequence_no<=(current_no-1)" fails.
Can any one suggest a solution to above?
If there is any difficuly in understanding question please comment..