> I have two 8-bit values, X & Y. Each can be anywhere within a range of say > 40 to 100 (allowance has to made for when one is zero). These linear values > represent the stored energy in two capacitors according to the function > 2^X(orY), where 100 is maximum, 90 a half, 80 a quarter, 70 an eighth etc. > including any integer value in between. > > I need to calculate a third value Z, an 8-bit value of the same form, > equivalent to the overall stored energy of both capacitors, again in the > range of say 40 to 100. e.g. If X=90 and Y=90 then Z=100 or if X=40 and Y=40 > then X=50 or if X=90 and Y=85 then Z=98 (approx.) > > Using LOG(base-2) the function Z = 10*lg(2^X/10 + 2^Y/10) does what I need > in Excel (with a bit of rounding), but I can't think of a simple way of > doing this in ASM. I need the code to be as tight and fast as possible. I don't know of any easy trick for trying to do addition in log space. You could use a table to convert from the log values to linear value, do the addition, then use a table again to convert back to this log space. That would be relatively fast but use a lot of code space. Why do the values need to be represented as they are? If you can store everything internally as linear energy values, it would simplify doing calculations like this. Do these values come in this way, need to go out this way? ******************************************************************** Olin Lathrop, embedded systems consultant in Littleton Massachusetts (978) 742-9014, olin@embedinc.com, http://www.embedinc.com -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.