|
Computer Science & Software Engineering C Programming (CITS1210) - Lecture 12 |
|
||||||
Storing multiple items in an integerThe most frequently seen example of C's bitwise operators, is the use of the left-shift operator to store multiple "items" in a single integer variable.Consider the following example, using an unsigned int to represent colours in an RGB format of 24 bits-per-pixel (24bpp):
Here, the left shift operator is used to quickly multiply a small value by a constant power of two. On most modern architectures, bit-shifting operations are considerably faster than the equivalent multiplications (use left-shifting) and divisions (use right-shifting). | |
|
C Programming (CITS1210), Lecture 12, p3, 23rd October 2008. |