Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
09/08/08 15:50
Read: times


 
#158078 - Its working but I have a question on theory
Responding to: ???'s previous message
Christoph,

I've used this exactly as:
unsigned long HC_Gain_temp;
unsigned int  HC_Gain_scaled;

HC_Gain_temp = 0x03A9 - 0x039A;
HC_Gain_temp = HC_Gain_temp * 0x80;

HC_Gain_temp = (HC_Gain_temp + (1 << 7)) >> 8;	// Divide by 256 with rounding

HC_Gain_scaled = (unsigned int) HC_Gain_temp + 0x039A;


and it works exactly as I want it too, with these and my other values as well. I don't understand how the rounding works. Could you or someone give me a leg up....it looks like your multiplying 1 and 128 (1 << 7) and adding it to the temp, which I don't really understand why......that is the only thing I don't understand what is happening within the equation.......everything else makes sense.

Thank you for helping me out and to everyone else who contributed

Thanks.....

List of 15 messages in thread
TopicAuthorDate
Scale offset using ints by byte position location            01/01/70 00:00      
   Does type casting make sense here?...            01/01/70 00:00      
      Show us more.........            01/01/70 00:00      
         Here are defs and original function            01/01/70 00:00      
      ints, at leastin Keil, at 16 bits wide.            01/01/70 00:00      
         Christoph,            01/01/70 00:00      
            That makes things clearer.            01/01/70 00:00      
               A detail            01/01/70 00:00      
            Take a look at the ranges            01/01/70 00:00      
               Brett, that is helpful, I should add....            01/01/70 00:00      
                  No floating-point math required.            01/01/70 00:00      
   Its working but I have a question on theory            01/01/70 00:00      
      Rounding instead of truncate            01/01/70 00:00      
         oh, that is interesting            01/01/70 00:00      
         Russ' comment is right, though.            01/01/70 00:00      

Back to Subject List