View Single Post
  #6   Spotlight this post!  
Unread 18-01-2008, 14:17
gnormhurst's Avatar
gnormhurst gnormhurst is offline
Norm Hurst
AKA: gnorm
#0381 (The Tornadoes)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Trenton, NJ
Posts: 138
gnormhurst will become famous soon enoughgnormhurst will become famous soon enough
Re: Reducing the sentivity of the joystick in easyC Pro

Instead of using a floating point constant like this:
Code:
foo = bar * 0.44;
you can do this:
Code:
foo = bar * 44 / 100;
Note that the following, with the divide operation first, is not the same, because integer division throws away any remainder:
Code:
foo = bar / 100 * 44; // BAD IDEA!
Even better (if bar is always positive) you could do this:
Code:
foo = (bar * 113) >> 8;
The " >> 8 " divides the result by 256 (shifts the bits to the right eight places). The value 113 is .44 times 256. Be sure to use an int type for bar (16 bits), not a char type (8 bits); The shift operator " >> " behaves unpredictably for negative numbers.
__________________
Trenton Tornadoes 381
2004 Philadelphia Regional Winners
2006 Xerox Creativity Award
---
My corner of the USPTO.
My favorite error message from gcc: main is usually a function
My favorite error message from Windows: There is not enough disk space available to delete this file.