wholly fractional numbers
Oh, of course you're not getting the expected result...
Let's see what you do here:
Code:
Value=(((char)(0.46*100)*(Ref_Lo - Value) + 50)/100) | 128;
First of all, your casting to
char does a lot of damage due to overflow. It's like doing modulus with 256 on every number and after every operation and that severely limits the range of your operations.
Look in my post above: i casted to a
long int just to avoid overflow and that's what you have to do as well.
Second, obtaining negative numbers it's
not just a matter of setting the most significant bit (MSB) in a number!
Negative numbers are internally encoded as
two's complement (see here: http://en.wikipedia.org/wiki/Two's_complement), which is tad more than just setting the MSB, but you don't have to know that because the machine will do the computations for you.
I'd do something like this:
Code:
if(Value < Ref_Lo && Value >= LowLim)
{
Value=(((int)(0.46*100)*(Value - Ref_Lo) - 50)/100);
Mask =Value;
}
Test it on paper for the extremes in the
Value range then debug and see if it's the right thing to do.
Arthur