Answer the question
In order to leave comments, you need to log in
How to calculate the value of a counter with a reset?
Good afternoon. There are many numbers in order from 0 to 65535, after 65535 the counter is reset. each value in the array is a timestamp, respectively, it can have such a situation [..., 65022, 12, n]. How to count the elements in this array so that the output would be [..., 65022, 65547, n]
Answer the question
In order to leave comments, you need to log in
The sequence can only be restored if the uncut numbers never change by more than 65535.
One solution is to add 65536 to the current number as long as it is less than the previous one. You can do with arithmetic:
a[i] += ceil((a[i-1]-a[i])/65536)*65536
Just check that in your language ceil(-0.5) gives 0, otherwise you need to separately check the case when the sequence increases at the beginning and nothing needs to be added. And yet, here it is considered that numbers in an uncut sequence can be repeated. If not, then we need to separately consider the case of equal numbers in the end and add 65536 again.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question