Hi all,
I understand that the left and right shift (<<, >>) operators shift bits around but can someone give me an example of when we would want to do this? I've read that left shift is equivalent to multiplication by two but if shifting a number ends up evaluating to another number, why not just hardcode that other number instead of shifting and having to calculate out what the shift is doing?
For example, in GObject we have things like:
Code:
#define G_TYPE_MAKE_FUNDAMENTAL(x) ((GType) ((x) << G_TYPE_FUNDAMENTAL_SHIFT))
where
Code:
#define G_TYPE_FUNDAMENTAL_SHIFT (2)
It appears the value to G_TYPE_MAKE_FUNDAMENTAL is therefore shifted two bits left. What's the point?