Hi, I know that you use this operator for the cout or for floating decimal spaces, but sometimes if find code like this:
(1<----------=Last Attacker=----------
ICQ: 120585863
E-mail: laextr@icqmail.com
Strange, didn''t even showed the rest, anyway, hope it comes out right this time:
"(1 << MAX_COUNT)";
----------=Last Attacker=----------
ICQ: 120585863
E-mail: laextr@icqmail.com
"(1 << MAX_COUNT)";
----------=Last Attacker=----------
ICQ: 120585863
E-mail: laextr@icqmail.com
<< is primarily the left shift operator. It has been overloaded for iostreams, but that is not their primary purpose. This operator shifts the bits of an integer a number of places to the left:
"A society without religion is like a crazed psychopath without a loaded .45"
unsigned char x = 1; // binary 00000001x = x << 2; // shift two places to the rightcout << (int)x << endl; //displays 4, which is binary 00000100x <<= 2; //same as x = x << 2cout << (int)x << endl; //displays 16, which is binary 00010000
"A society without religion is like a crazed psychopath without a loaded .45"
The effects of a bitshift:
it is an immensely efficient method of multiplying and dividing by powers of 2.
a << 1 = a * 2
a << 2 = a * 4
a << 3 = a * 8
etc.
a << b = a * 2^ba >> b - a / 2^b
it is an immensely efficient method of multiplying and dividing by powers of 2.
a << 1 = a * 2
a << 2 = a * 4
a << 3 = a * 8
etc.
I''ve read about bit shifting in assembly, but didn''t know how to do this in C++. Now atleast I know that. Thanks!
----------=Last Attacker=----------
ICQ: 120585863
E-mail: laextr@icqmail.com
----------=Last Attacker=----------
ICQ: 120585863
E-mail: laextr@icqmail.com
I''ve read about bit shifting in assembly, but didn''t know how to do this in C++. Now atleast I know that. Thanks!
----------=Last Attacker=----------
ICQ: 120585863
E-mail: laextr@icqmail.com
----------=Last Attacker=----------
ICQ: 120585863
E-mail: laextr@icqmail.com
B.T.W. what is bit shifting good for?
----------=Last Attacker=----------
ICQ: 120585863
E-mail: laextr@icqmail.com
----------=Last Attacker=----------
ICQ: 120585863
E-mail: laextr@icqmail.com
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement