regarding bitwise shift in "eventloop.h"
seanegan at gmail.com
Wed Aug 1 01:42:08 EDT 2007
On 7/31/07, Harry Tanama <pr0gm3r at gmail.com> wrote:
> I don't really understand the purpose of using bitwise left-shift in
> constant value of PurpleInputCondition enum.
> 4 is 100 in binary. Adding 2 zeros to the end gives 10000, which is 16, i.e.
> 4*22 = 4*4 = 16. I don't quiet understand why we're doing arithmetic binary
> in the
> PURPLE_INPUT_READ = 1 << 0, and PURPLE_INPUT_WRITE = 1 << 1
Hi, Harry. These values are binary flags. One 32-bit integer value can
hold 32 of these flags.
If we were to have a third flag, it would be 1 << 3, 100 in binary, 4
in decimal. Then 1 << 4 (8), 1 << 5 (16), etc.
Setting the values to bit-shifted constants is just slightly more
readable than setting them to constant powers of two.
Any good compiler will optimize those values as not to require any
calculation at runtime.
More information about the Devel