In SX Microcontrollers, SX/B Compiler and SX-Key Tool, InSilico wrote: It depends on what encoding you used to store negative numbers. The most common method (aka just about every computer I know uses this) is Two's complement: [url=http://en.wikipedia.org/wiki/Two's_complement]http://en.wikipedia.org/wiki/Two's_complement[/url] In your code you're setting the 7th bit of ticks as "1" to indicate a negative number. This is not how it is done in Two's complement. Positive numbers are represented "normally" as a binary number. For example: 45 (decimal) --> 00101101 (binary) To get -45, you first invert the bits and add one: 00101101 --> 11010010 --> (1s become 0s, 0s become 1s) 11010011 (added 1 to the number) So now -45 (decimal) --> 11010011 (binary) in two's complement The cool thing about Two's complement is that you don't have to do anything else for addition and subtraction. "Normal" add and subtract functions will work on two's complement binary numbers. Note that with Two's complement on 8 bits, the possible range is -128 to 127. Two's complement on 16 bits (a word) is done exactly the same way, except with a range of -65536 to 65535. Take a closer look at how Two's complement works, then this problem becomes much easier. Hope this helps! ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=288040#m288662 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2008 (http://www.dotNetBB.com)