"<<" ??

Started by
11 comments, last by Last Attacker 22 years, 6 months ago
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
"Take delight in the Lord and He will give you your heart's desires" - Psalm 37:4My Blog
Advertisement
Could you repeat that???

/Mankind gave birth to God.
/Mankind gave birth to God.
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
"Take delight in the Lord and He will give you your heart's desires" - Psalm 37:4My Blog
<< 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:
  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"
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
It''s called bitshifting.

or did you already know this?


/Mankind gave birth to God.
/Mankind gave birth to God.
The effects of a bitshift:

  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.
This is my signature. There are many like it, but this one is mine. My signature is my best friend. It is my life. I must master it as I must master my life. My signature, without me, is useless. Without my signature, I am useless.
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
"Take delight in the Lord and He will give you your heart's desires" - Psalm 37:4My Blog
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
"Take delight in the Lord and He will give you your heart's desires" - Psalm 37:4My Blog
B.T.W. what is bit shifting good for?


----------=Last Attacker=----------

ICQ: 120585863
E-mail: laextr@icqmail.com
"Take delight in the Lord and He will give you your heart's desires" - Psalm 37:4My Blog
quick math... faster than divide or multiply by 2.

a2k
------------------General Equation, this is Private Function reporting for duty, sir!a2k

This topic is closed to new replies.

Advertisement