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 07:17
Read: times


 
#158039 - ints, at leastin Keil, at 16 bits wide.
Responding to: ???'s previous message
Chris Bertrand said:
HC_Gain_scaled = (((HC_GAIN_HIGH - HC_GAIN_LOW) * (uint)pot_level)) >> 16; //Average and divide by 65535


ints, at least in Keil C51, are 16 bits wide, so shifting them 16 bits to the right will result in 0x0000.

Also, since HC_GAIN_LOW and HC_GAIN_HIGH are ints (by default, you can make them something else with the appropriate specifier), the cast should have no effect since pot_level is implicitly cast to an int.

I'm still not quite sure what problem you are trying to describe. Can you give an example (code, values, expected output, actual output)? That would be helpful for figuring things out.

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