What happens if the average is 180, and the readings are 178, 179, 181=20 and 182? Kerry IVP wrote: > Hi Richard, > =20 > =20 >> 358, 359, 1 and 2 degrees >> =20 > > -2, -1, 1, 2 ? > > IOW, express the 0 - 359 as relative to 179 (centre point for the > mathematical polarity), the same way that a byte can represent -127 > to 128 in signed maths. In that instance, bit 7 denotes polarity, and > =20 >> =3D 128 (b1000000 to b11111111) is negative >> =20 > > So, you do a magnitude test for > 179 and, if so, subtract the > value from 360 > > Because of the limited range you can keep the result in one byte > but bit7 can't be used as the polarity indicator (rules out comf/ > negation too) so you'll need to have another bit > > eg > > value =3D 358 (is > 179) =3D> 360 - 358 =3D -2 > value =3D 192 (is >179) =3D> 360 - 192 =3D -168 > > value =3D 0 (is < 180) =3D> +0 > value =3D 179 (is < 180) =3D> +179 > > Joe > =20 --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .