Their use and meaning depends entirely on context. For built-in integral types, they are bitwise operators for bit-shifting operations. Under these circumstances, << means "shift left" and >> means "shift right".
More commonly, you see them in C++ for input and output. Under these circumstances, << means "Outputs to" and >> means "Gets input from"
the two most common examples -
std::cout << "Enter a number: ";
std::cin >> i;
Line 6 of the code could be translated to read
"Enter a number: " Outputs to std::cout
Line 7 of the code could be translated to read
variable 'i' Gets input from std::cin
In both cases, the statements are read right-to-left in the code snippet.
Right shifting 1 by 8, 16 or 24 times isn't going to get you anywhere. After a single right shift, the number will become 0 and 'AND'ing it with any number would make no difference. Oh and BTW, 0XF is the same as 0XFF or 0XFFFFFFFF.
Try something like:
int x,y,z, i = 16;
x = (unsigned char) (i >> 2 & 0xff );
y = (unsigned char) (i >> 3 & 0xF );
z = (unsigned char) (i >> 4 & 0xFFFFFFFF );
cout << "Original number: " << i << '\n';
cout << "x=" << x << endl;
cout << "y=" << y << endl;
cout << "z=" << z << endl;
hello there, can anyone here explain to me and an explanation on the usage of these operators (<< and >>) or point me to any site that explains it very well... thank you... :)
these operators are bitwise operators....
>>is shift right operator...<< is shift left operator...
>> operator will shift as many bits as you want towards right side...
and<<operator will shift as many bits as you want towards left...
fo eg::if you shift 1 one bit toward left..now it will be10...
if we shift towards left a o will be added to right itz like mutiplying the number by 2(1X2=2 in binary itz 10)...and vice versa...
but they are commonly used for cout and cin in c++...