You are forgetting the mathematical overflow. Suppose you set the limits at +25 (lower) and +100 (upper ). Value read: +10 +10 - ( +25 ) =3D -15 +10 - ( +100 ) =3D -90 So it is below both limits Value read: +30 +30 - ( +25 ) =3D +5 +30 - ( +100 ) =3D -70 So it is between the lower and the upper limits. Value read: +120 +120 - ( +25 ) =3D +95 +120 - ( +100 ) =3D +20 So it is above both limits. But suppose you read -50 -50 - ( +25 ) =3D -75 -50 - ( +100 ) =3D -150 <=3D problem here. A 8-bit two's complement number can not go below -128 -50 in two's complement is 206 and -100 is 156, so the above subtraction becomes: 206 + 156 =3D 362. This number gets truncated to 106, which is positive. That=B4s right: 206 + 156 =3D 106 !!! You must test the OVERFLOW bit also, but the 12-bit and 14-bit instruction PICs do not have it. The PIC18 has. You will need to do more tests and calculations to get the correct result. David Duffy escreveu: > It's signed (two's complement) format. The MSB is the sign. (set when = > negative) > David... > > Tamas Rudnai wrote: > = >> Sorry, I do not get it, how do you make difference if +5 or -5 is less t= han >> -128 ? >> Or -120 or +120 is less than -128? >> >> Tamas >> = __________________________________________________ Fa=E7a liga=E7=F5es para outros computadores com o novo Yahoo! Messenger = http://br.beta.messenger.yahoo.com/ = -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist