468,490 Members | 2,558 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,490 developers. It's quick & easy.

What does << mean in C++?

What does the following macro mean, especially the << sign:

#define hello(x) (( int64 ) floor( (double) x ) << 32)

Thanks
Thierry

Aug 8 '06 #1
10 46124
Thierry Lam wrote:
What does the following macro mean, especially the << sign:

#define hello(x) (( int64 ) floor( (double) x ) << 32)
You should get a C++ book. This is a very basic concept. << is the bit shift
operator. Here, it means that the value on the left side should be shift
left by 32 bits.

Aug 8 '06 #2
Rolf Magnus wrote:
Thierry Lam wrote:
What does the following macro mean, especially the << sign:

#define hello(x) (( int64 ) floor( (double) x ) << 32)

You should get a C++ book.
Agreed. There's a good, free one here:

http://mindview.net/Books/TICPP/ThinkingInCPP2e.html

or get _Accelerated C++_ by Koenig and Moo, which is the best IMHO.

Cheers! --M

Aug 8 '06 #3
mlimber wrote:
Rolf Magnus wrote:
>>Thierry Lam wrote:

>>>What does the following macro mean, especially the << sign:

#define hello(x) (( int64 ) floor( (double) x ) << 32)

You should get a C++ book.


Agreed. There's a good, free one here:

http://mindview.net/Books/TICPP/ThinkingInCPP2e.html

or get _Accelerated C++_ by Koenig and Moo, which is the best IMHO.

Cheers! --M
C++ has nothing to do with it... looks like it is just finding the
mathematical floor of the variable x (largest integral value less than
or equal to x) and right shifting it into the 4 most significant bytes...

Aug 8 '06 #4
Jeremy Brown wrote:
mlimber wrote:
>Rolf Magnus wrote:
>>Thierry Lam wrote:
What does the following macro mean, especially the << sign:

#define hello(x) (( int64 ) floor( (double) x ) << 32)
You should get a C++ book.

Agreed. There's a good, free one here:

http://mindview.net/Books/TICPP/ThinkingInCPP2e.html

or get _Accelerated C++_ by Koenig and Moo, which is the best IMHO.

Cheers! --M
C++ has nothing to do with it... looks like it is just finding the
mathematical floor of the variable x (largest integral value less than
or equal to x) and right shifting it into the 4 most significant bytes...
sorry... I meant l-shift

Aug 8 '06 #5

"Jeremy Brown" <bj*****@bnr.cawrote in message
news:44**************@bnr.ca...
Jeremy Brown wrote:
>mlimber wrote:
>>Rolf Magnus wrote:

Thierry Lam wrote:
What does the following macro mean, especially the << sign:
>
#define hello(x) (( int64 ) floor( (double) x ) << 32)
You should get a C++ book.

Agreed. There's a good, free one here:

http://mindview.net/Books/TICPP/ThinkingInCPP2e.html

or get _Accelerated C++_ by Koenig and Moo, which is the best IMHO.

Cheers! --M
C++ has nothing to do with it... looks like it is just finding the
mathematical floor of the variable x (largest integral value less than or
equal to x) and right shifting it into the 4 most significant bytes...
sorry... I meant l-shift
So, why does that have nothing to do with C++? The << symbol represents the
C++ operator which performs that function. And if one doesn't know what
that symbol means, then a good C++ book will give them that, along with all
the other valid C++ symbols. Looks like it was good advice to me...

-Howard


Aug 8 '06 #6

Thierry Lam skrev:
What does the following macro mean, especially the << sign:

#define hello(x) (( int64 ) floor( (double) x ) << 32)

Thanks
Thierry
In C++, << is normally the stream-operator - used e.g. for outputting
variables. In low-level code it can also be used for bitshifting -
which previously was used sometimes for optimising
multiplication/division. Today, you gain nothing in speed and you
should avoid usage of the operator for stuff of this type.
In the example above, to the best of my knowledge the result of the
macro is undefined as shifts of an int64 is implementation-defined. (Of
course - so is int64).

/Peter

Aug 8 '06 #7

"peter koch" <pe***************@gmail.comwrote in message
news:11*********************@m73g2000cwd.googlegro ups.com...
>
Thierry Lam skrev:
>What does the following macro mean, especially the << sign:

#define hello(x) (( int64 ) floor( (double) x ) << 32)

Thanks
Thierry

In C++, << is normally the stream-operator - used e.g. for outputting
variables. In low-level code it can also be used for bitshifting -
which previously was used sometimes for optimising
multiplication/division. Today, you gain nothing in speed and you
should avoid usage of the operator for stuff of this type.
In the example above, to the best of my knowledge the result of the
macro is undefined as shifts of an int64 is implementation-defined. (Of
course - so is int64).
Bit shifting is not obsolete, or unnormal, by any means. It's not always an
attempt at speeding up multiplication. Sometimes it is used as a portable
way to read bytes whose order might differ between platforms. The results
are guaranteed, regardless of endian-ness (provided they're used on integral
types for which the results are defined, naturally).

It's also used for bit-masking, allowing you store more information in one
location.

Also, if shifts of an int64 is implementation-defined, then the result of
the above macro is also implementation-defined, not undefined. There's a
difference.

-Howard
Aug 8 '06 #8

peter koch wrote:
Thierry Lam skrev:
What does the following macro mean, especially the << sign:

#define hello(x) (( int64 ) floor( (double) x ) << 32)

Thanks
Thierry

In C++, << is normally the stream-operator - used e.g. for outputting
variables.
Only wrt streams. In C++ << means whatever it is defined to mean given
the context. << as defined for std::bitset for instance has a totally
different meaning.

In low-level code it can also be used for bitshifting -
which previously was used sometimes for optimising
multiplication/division.
Bitshifting's used for a lot more than that.

Today, you gain nothing in speed and you
should avoid usage of the operator for stuff of this type.
Bah...it's exactly what the operator is built for.

Aug 8 '06 #9

Howard skrev:
"peter koch" <pe***************@gmail.comwrote in message
news:11*********************@m73g2000cwd.googlegro ups.com...

Thierry Lam skrev:
What does the following macro mean, especially the << sign:

#define hello(x) (( int64 ) floor( (double) x ) << 32)

Thanks
Thierry
In C++, << is normally the stream-operator - used e.g. for outputting
variables. In low-level code it can also be used for bitshifting -
which previously was used sometimes for optimising
multiplication/division. Today, you gain nothing in speed and you
should avoid usage of the operator for stuff of this type.
In the example above, to the best of my knowledge the result of the
macro is undefined as shifts of an int64 is implementation-defined. (Of
course - so is int64).

Bit shifting is not obsolete, or unnormal, by any means. It's not always an
attempt at speeding up multiplication. Sometimes it is used as a portable
way to read bytes whose order might differ between platforms. The results
are guaranteed, regardless of endian-ness (provided they're used on integral
types for which the results are defined, naturally).

It's also used for bit-masking, allowing you store more information in one
location.
I absolutely agree that those are valid uses. Stiil, it would be much
better to use an unsigned integral value. This frees you of lots of
surprises.
>
Also, if shifts of an int64 is implementation-defined, then the result of
the above macro is also implementation-defined, not undefined. There's a
difference.
I agree here as well. Slip of the mind.

>
-Howard
Aug 8 '06 #10
On 8 Aug 2006 14:35:13 -0700, "peter koch"
<pe***************@gmail.comwrote in comp.lang.c++:
>
Thierry Lam skrev:
What does the following macro mean, especially the << sign:

#define hello(x) (( int64 ) floor( (double) x ) << 32)

Thanks
Thierry

In C++, << is normally the stream-operator - used e.g. for outputting
variables. In low-level code it can also be used for bitshifting -
which previously was used sometimes for optimising
multiplication/division. Today, you gain nothing in speed and you
should avoid usage of the operator for stuff of this type.
In the example above, to the best of my knowledge the result of the
macro is undefined as shifts of an int64 is implementation-defined. (Of
course - so is int64).
Very misleading, bordering on incorrect. In the C++ language, the <<
operator is specifically defined as the bit-wise left shift operator
for integral types. It always has been, it always will be, and it
cannot be changed.

It is common practice to overload this operator for user-defined types
as a stream insertion operator when applied to a reference to a
stream. This overload is supplied by several stream classes included
in the standard C++ library. But it does not change the original
meaning of the operator.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Aug 8 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by serge calderara | last post: by
2 posts views Thread by Steve Richter | last post: by
3 posts views Thread by RobertTG | last post: by
92 posts views Thread by Heinrich Pumpernickel | last post: by
45 posts views Thread by loudking | last post: by
reply views Thread by NPC403 | last post: by
3 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.