4/06/2007

ShiFter

I have written lines of code with mathematical operators...but i always wonder about shiFters (Shift Operators...Bingo!)...
Why do we need it...? watz the use...? Read on...
1. Make faster integer division/multiplication operations:

4839534 * 4
can be done like this:
4839534 << 2

or

543894 / 2
can be done like this:
543894 >> 1

Shift operations much more faster than multiplication for most of processors.

2. Reassembling byte streams to int values
3. For accelerating operations with graphics since Red, Green and Blue colors coded by separate bytes.
4. Packing small numbers into one single long...

No comments:

dzone.com