Steve Church

finding magnitude of difference between two numbers

Discussion created by Steve Church on May 15, 2012
Latest reply on May 21, 2012 by bigmac

I have a particular requirement to determine the magnitude  of the difference between two 16 bit values (not the sign). The max value of each number is 8191 before it wraps around to zero so I need to account for this. In my application I have a 16 bit  count going up or down (yes I know 8191 is 13 bits..but it's held in two bytes). I must compare the previous count value with the current count value and determine the magnitude of the difference taking into account the wrap round ( so old value = 8190, new value is 2...difference is 4 not 8188). The max value of this magnitude is likely to be less than ten.


Any thoughts? I am having to get back into thinking at assembler level again to support a legacy project. I have been writing in C for several years and am a bit rusty!

Oh it's for HC08.