keyword <<

Hi,i have one question about '<<', i see it when i use the marco RGB, anyone can tell me what it is?Thanks in advance.
Last edited on
when used with streams (cout, for example), it's overloaded to be an "insertion" operator (<<) or "extraction" operator (>>).

However normal usage is a bitshift operation. << is a left shift and >> is a [arithmatic] right shift. This shifts each bit in a value left or right by the given number of bits.

1
2
3
4
unsigned char abyte = 0x17;  // 0x17 = 00010111
abyte <<= 1;  // left shift by 1:
//  00010111  <-  0x17
//  00101110  <-  0x2E (0x17 left shift 1) 


In practice, << X has effectively the same result as * 2X and >> X has nearly the same result as / 2X (nearly because rounding/truncating is handled differently). Shifting can only be done on intergral types (not on floating points).
Last edited on
Thanks
Topic archived. No new replies allowed.