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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
07/17/12 05:21
Read: 487 times

#187956 - How does this look?
Responding to: Oliver Sedlacek's previous message
Perfect, thanks for the suggestions, guys!

I tried a few different approaches and decided to use this function for right shifting:

signed short RightShift(signed short NumToShift, unsigned char NumBitsShift)
	NumToShift >>= (NumBitsShift - 1);
	NumToShift = NumToShift + 1;
	NumToShift >>= 1;
	return NumToShift;


It seems to solve my shifting problem and should be faster than a division operator. Does that look ok or would you recommend another approach? I know Per Westermark suggested adding a number based on the number of shifts but if I either need to have multiple cases (which is possible) or I need to add 2^(NumBitsToShift-1) and I believe the ^ operator takes a long time. So it looks like this is the best approach.

If I'm wrong, let me know (I'm still a bit rusty on my C coding). Thanks!

List of 9 messages in thread
Right Shift Rounding Recommendations      Jeremy Brookley      07/16/12 10:30      
   add before shift      Per Westermark      07/16/12 11:12      
   Guard digits?      Oliver Sedlacek      07/16/12 22:25      
      How does this look?      Jeremy Brookley      07/17/12 05:21      
         Nice but..      Oliver Sedlacek      07/18/12 09:55      
   Please elaborate further.      Christoph Franck      07/19/12 04:33      
             Jeremy Brookley      07/19/12 10:02      
      I do not know how you managed, but      Erik Malund      07/19/12 12:48      
         breaking the rules, one forum at a time . . .      Jeremy Brookley      07/19/12 13:59      

Back to Subject List