I've got a modulo arithmetic question to do with a sensor outputting data like this: bits 31-26 ID and parity bits 25,24,23 modulo counter bits 22-0 data (LSB bit = 42.91534 micro degrees) The 3-bit modulo counter increments when crossing from 359 to 0 deg and decrements when crossing from 0 to 359 deg. I want to find the difference between the current reading of the sensor and the previous reading. Using the the least sig bit of the modulo gives angle polarity but only for the rollover between +-360deg. Here is a table of rollover points as I rotate the sensor a few turns in either direction. DEG/MOD/DATA msb of data 2881 000 0 2879 111 1 2521 111 0 2519 110 1 . . 1079 010 1 721 010 0 719 001 1 361 001 0 359 000 1 +0 000 0 -0 111 1 -359 111 0 -361 110 1 -719 110 0 -721 101 1 -1079 101 0 . . -2519 001 0 -2521 001 1 -2879 000 0 -2881 111 1 Is there some way to get angle polarity from the modulo at higher rollovers, eg 719-721 etc and so work out which way the sensor has turned so that after the previous reading has been subtracted from the current, the difference indicates the angle and direction, of the sensor movement. Thanks for any replies, Brian Harris -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist