473,473 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

The << symbol.

Hi everyone hope you are all ok.

Just learning C++ (as you can tell from the noob question Im about to
ask). One symbol/function/assignment/whatever really bothers me which
is the "<<" one.

I saw this line of code:

#define IN_VALIDINPUT (1 << 16)

And its meaning totally stumps me. I know that << gets used for like:

cout << "My name isnt Ishmael";

and that these can stack up:

cout << "My name isnt Ishmael, Its " << name << "You fool.";

but I dont understand if these 2 contexts for << are even the same. I
also know that there is a similar thing just the opposite facing (>>)
but again the use stumps me.

Sorry if this is a silly line of questioning but searching for
anything on the topic of "<<" throws up endless tutorial programs full
of:
cout << "Hello World^42";

could really do with some guidance.

Mar 3 '07 #1
8 1591
ma********@googlemail.com wrote:
Just learning C++ (as you can tell from the noob question Im about to
ask). One symbol/function/assignment/whatever really bothers me which
is the "<<" one.

I saw this line of code:

#define IN_VALIDINPUT (1 << 16)
It's an operator meaning "left shift" for integral values.
And its meaning totally stumps me. I know that << gets used for like:

cout << "My name isnt Ishmael";
That operator is overloadable and it has a different meaning for
the 'cout' object.
and that these can stack up:

cout << "My name isnt Ishmael, Its " << name << "You fool.";

but I dont understand if these 2 contexts for << are even the same. I
also know that there is a similar thing just the opposite facing (>>)
but again the use stumps me.
Yes, for integers the >means "right shift". And it's also overloaded
for streams and it means something different there.
Sorry if this is a silly line of questioning but searching for
anything on the topic of "<<" throws up endless tutorial programs full
of:
cout << "Hello World^42";

could really do with some guidance.
You should allow those symbols to mean different things for now and
you will learn later _how_ it's possible that they mean different
things for different objects.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Mar 3 '07 #2

"It's an operator meaning "left shift" for integral values."

integral values? do you mean integers?

Also do you mean a bitwise left shift. so 2 becomes 4 when shifted
once, 64 becomes 256 when shifted twice? Am I thinking back to my
Verilog days too much here?

Mar 3 '07 #3
ma********@googlemail.com wrote:
"It's an operator meaning "left shift" for integral values."

integral values? do you mean integers?
Essentially. C++ has a number of integral types (types that can hold
integers), that vary in the range they can express (and, usually, in the
number of bytes used to represent them).
>
Also do you mean a bitwise left shift. so 2 becomes 4 when shifted
once, 64 becomes 256 when shifted twice?
Yes.

--
Alan Johnson
Mar 3 '07 #4
On Mar 3, 1:44 am, Alan Johnson <a...@yahoo.comwrote:
markeng...@googlemail.com wrote:
"It's an operator meaning "left shift" for integral values."
integral values? do you mean integers?

Essentially. C++ has a number of integral types (types that can hold
integers), that vary in the range they can express (and, usually, in the
number of bytes used to represent them).
Also do you mean a bitwise left shift. so 2 becomes 4 when shifted
once, 64 becomes 256 when shifted twice?

Yes.

--
Alan Johnson
Thats awesome thanks people.

Mar 3 '07 #5
On Mar 3, 1:44 am, Alan Johnson <a...@yahoo.comwrote:
markeng...@googlemail.com wrote:
"It's an operator meaning "left shift" for integral values."
integral values? do you mean integers?

Essentially. C++ has a number of integral types (types that can hold
integers), that vary in the range they can express (and, usually, in the
number of bytes used to represent them).
Also do you mean a bitwise left shift. so 2 becomes 4 when shifted
once, 64 becomes 256 when shifted twice?

Yes.

--
Alan Johnson
Thats awesome thanks people.

Mar 3 '07 #6
On Mar 3, 6:19 am, markeng...@googlemail.com wrote:
Hi everyone hope you are all ok.

Just learning C++ (as you can tell from the noob question Im about to
ask). One symbol/function/assignment/whatever really bothers me which
is the "<<" one.

I saw this line of code:

#define IN_VALIDINPUT (1 << 16)

And its meaning totally stumps me. I know that << gets used for like:

cout << "My name isnt Ishmael";

and that these can stack up:

cout << "My name isnt Ishmael, Its " << name << "You fool.";

but I dont understand if these 2 contexts for << are even the same. I
also know that there is a similar thing just the opposite facing (>>)
but again the use stumps me.

Sorry if this is a silly line of questioning but searching for
anything on the topic of "<<" throws up endless tutorial programs full
of:
cout << "Hello World^42";

could really do with some guidance.
The '<<' in C has a different meaning (left shift bitwise operator)
that is if i do 2<<1, the result would be 4. But because of operator
overloading concept in C++, that is we can have different meaning of
the operator, the "<<" operator is overloaded in C++ for standard
input/output streams hence when you have cout<<"Hello World";, its the
overloaded operator that would be invoked as cout is the object here.
But if you have same operator with integer values on both sides, it
would be a general bitwise shift left. For further reference see
Design and Evolution of C++ by Bjarne Stroustrup

Mar 3 '07 #7
On Mar 3, 8:25 am, "dervaish" <unmeshgh...@gmail.comwrote:
On Mar 3, 6:19 am, markeng...@googlemail.com wrote:
Hi everyone hope you are all ok.
Just learning C++ (as you can tell from the noob question Im about to
ask). One symbol/function/assignment/whatever really bothers me which
is the "<<" one.
I saw this line of code:
#define IN_VALIDINPUT (1 << 16)
And its meaning totally stumps me. I know that << gets used for like:
cout << "My name isnt Ishmael";
and that these can stack up:
cout << "My name isnt Ishmael, Its " << name << "You fool.";
but I dont understand if these 2 contexts for << are even the same. I
also know that there is a similar thing just the opposite facing (>>)
but again the use stumps me.
Sorry if this is a silly line of questioning but searching for
anything on the topic of "<<" throws up endless tutorial programs full
of:
cout << "Hello World^42";
could really do with some guidance.

The '<<' in C has a different meaning (left shift bitwise operator)
that is if i do 2<<1, the result would be 4. But because of operator
overloading concept in C++, that is we can have different meaning of
the operator, the "<<" operator is overloaded in C++ for standard
input/output streams hence when you have cout<<"Hello World";, its the
overloaded operator that would be invoked as cout is the object here.
But if you have same operator with integer values on both sides, it
would be a general bitwise shift left. For further reference see
Design and Evolution of C++ by Bjarne Stroustrup
Hmm thanks, Id heard people say that operator was overloaded but that
makes sense of it. Also it occured to me to ask if there is any way
to check the carry for this operation, or for any other bitwise
operation for that matter?

Mar 3 '07 #8
ma********@googlemail.com wrote:
Hmm thanks, Id heard people say that operator was overloaded but that
makes sense of it. Also it occured to me to ask if there is any way
to check the carry for this operation, or for any other bitwise
operation for that matter?
Nope, because shifting left and creating a value bigger than the
underlying integral type can represent is undefined behavior.
Mar 3 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

129
by: Torbjørn Pettersen | last post by:
I've started cleaning up my HTML and implementing CSS. So far I've used FrontPage, but am switching over to DreamWeaver. Reading a bit on W3Schools.com and W3.org I see there are a lot of HTML...
4
by: Dan | last post by:
Hi, I would just like to know if the istream operator takes only one parammeter(object) at a time (like z) ? istream operator>>(istream& in, Shape &z) Cause I keep getting error concerning the...
0
by: Raven | last post by:
When switching from VC7.0 to VC7.1 I've encountered a problem: I have a plugin class like class ATL_NO_VTABLE CDataFlowPlugIn : public CComObjectRootEx<CComSingleThreadModel>, public...
3
by: silverburgh.meryl | last post by:
I have this linker error, and I would need some help in resolving it: I have put "#include <iostream>" in my .cpp. I am not sure why I can't link. It compiles fine. /usr/bin/ld:...
1
by: sharmadeep1980 | last post by:
Hi All, I am facing a very unique problem while compling my project in "Release" build. The project is building in DEBUG mode but giving linking error on Release build. Here is the error:...
10
by: Thierry Lam | last post by:
What does the following macro mean, especially the << sign: #define hello(x) (( int64 ) floor( (double) x ) << 32) Thanks Thierry
49
$
by: google | last post by:
what dose a $ do in javascript, i have been given a bit of code and there are $'s all over the place, can someone explain their uses
4
by: rengaraj | last post by:
Sir / Mam, I can replace < with &lt; or &60# and 62 for > But, If i need the following text <code># include <stdio.h> </code> i will write as <code># include &lt; stido.h &gt;</code> it displays...
4
by: Tex08 | last post by:
I did it again... after trashing the old code and trying to start simple, I receive the following error at compile (with g++, required)" g++ main.cc Undefined first...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.