| ??? 07/17/12 11:21 Read: times |
#187956 - How does this look? Responding to: ???'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! |
| Topic | Author | Date |
| Right Shift Rounding Recommendations | 01/01/70 00:00 | |
| add before shift | 01/01/70 00:00 | |
| Guard digits? | 01/01/70 00:00 | |
| How does this look? | 01/01/70 00:00 | |
| Nice but.. | 01/01/70 00:00 | |
| Please elaborate further. | 01/01/70 00:00 | |
| 01/01/70 00:00 | ||
| I do not know how you managed, but | 01/01/70 00:00 | |
breaking the rules, one forum at a time . . . | 01/01/70 00:00 |



