In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Johnson Rod wrote: i tried to explain it well. i really dint think this was so complex untill this little proof my algorithm goes like so if valHi > valLo then result_cw = valHi - valLo result_ccw = 512 - (valHi - valLo) = 512 + valLo - valHi yours states mask = $01 result_cw = valHi - valLo result_ccw = valLo - valHi // 256 = [calcultator] ((65536 + valLo - valHi) / 256 - 255) * 256) ((65535 + valLo - valHi) / 256 - 255) * 256 ?= 512 + valLo - valHi 65536 + valLo - valHi - 65280 ?= 512 + valLo - valHi 256 + valLo - valHi) ?= 512 + valLo - valHi 256 != 512 ok so your algy wraps around 255 (8bits) if we change the mask to $03... result_ccw = valLo - valHi // 512 = [calculator] ((65536 + valLo - valHi) / 512 - 127) * 512 66536 + valLo - valHi - 65024 = 512 + valLo - valHi 512 == 512 *SUCCESS* so you can also div by the wrap around value to do circular arithmatic! i honestly did not think it was that simple many thanks tracy ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=89622#m89764 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2005 (http://www.dotNetBB.com)