PDA

View Full Version : Check within a 16 bytes window



Ioannis
- 28th November 2012, 17:46
Here is the problem.

I have a counter that is 16 bits wide. Also another 16 bits counter.

I need to check if the distance between them is no more that 16 bytes.

The tricky part is where the one is near the roll over and the other has already rolled.

For example one counter is at FFFC and the other is at 0003.

Any ideas?
Ioannis

Darrel Taylor
- 28th November 2012, 18:18
IF ABS(count1 - count2) > 16 THEN ...

Ioannis
- 28th November 2012, 20:12
Every time I get an answer by Darrel, I feel I have to hide somewhere... Embarassed.

Thanks Darrel.
Ioannis

Darrel Taylor
- 28th November 2012, 23:18
Well, don't feel too bad, cause I'm not even sure that will work under all conditions.

I should do some testing.

Darrel Taylor
- 29th November 2012, 02:43
After some testing ... it does work.

Now I want to hide. :o

Ioannis
- 29th November 2012, 11:54
I just did not think in terms of pure binary maths. So trying to find a way with 10 base mind was driving me away from the clear solution you gave.

Thanks again.
Ioannis