Connecting Tech Pros Worldwide Forums | Help | Site Map

What does << mean in C++?

Thierry Lam
Guest
 
Posts: n/a
#1: Aug 8 '06
What does the following macro mean, especially the << sign:

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

Thanks
Thierry


Rolf Magnus
Guest
 
Posts: n/a
#2: Aug 8 '06

re: What does << mean in C++?


Thierry Lam wrote:
Quote:
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.

mlimber
Guest
 
Posts: n/a
#3: Aug 8 '06

re: What does << mean in C++?


Rolf Magnus wrote:
Quote:
Thierry Lam wrote:
>
Quote:
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

Jeremy Brown
Guest
 
Posts: n/a
#4: Aug 8 '06

re: What does << mean in C++?


mlimber wrote:
Quote:
Rolf Magnus wrote:
>
Quote:
>>Thierry Lam wrote:
>>
>>
Quote:
>>>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...

Jeremy Brown
Guest
 
Posts: n/a
#5: Aug 8 '06

re: What does << mean in C++?


Jeremy Brown wrote:
Quote:
mlimber wrote:
>
Quote:
>Rolf Magnus wrote:
>>
Quote:
>>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

Howard
Guest
 
Posts: n/a
#6: Aug 8 '06

re: What does << mean in C++?



"Jeremy Brown" <bjeremy@bnr.cawrote in message
news:44D8E4BA.5040201@bnr.ca...
Quote:
Jeremy Brown wrote:
Quote:
>mlimber wrote:
>>
Quote:
>>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




peter koch
Guest
 
Posts: n/a
#7: Aug 8 '06

re: What does << mean in C++?



Thierry Lam skrev:
Quote:
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

Howard
Guest
 
Posts: n/a
#8: Aug 8 '06

re: What does << mean in C++?



"peter koch" <peter.koch.larsen@gmail.comwrote in message
news:1155072913.138232.47920@m73g2000cwd.googlegro ups.com...
Quote:
>
Thierry Lam skrev:
>
Quote:
>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


Noah Roberts
Guest
 
Posts: n/a
#9: Aug 8 '06

re: What does << mean in C++?



peter koch wrote:
Quote:
Thierry Lam skrev:
>
Quote:
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 -
Quote:
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
Quote:
should avoid usage of the operator for stuff of this type.
Bah...it's exactly what the operator is built for.

peter koch
Guest
 
Posts: n/a
#10: Aug 8 '06

re: What does << mean in C++?



Howard skrev:
Quote:
"peter koch" <peter.koch.larsen@gmail.comwrote in message
news:1155072913.138232.47920@m73g2000cwd.googlegro ups.com...
Quote:

Thierry Lam skrev:
Quote:
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.
Quote:
>
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.

Quote:
>
-Howard
Jack Klein
Guest
 
Posts: n/a
#11: Aug 9 '06

re: What does << mean in C++?


On 8 Aug 2006 14:35:13 -0700, "peter koch"
<peter.koch.larsen@gmail.comwrote in comp.lang.c++:
Quote:
>
Thierry Lam skrev:
>
Quote:
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
Closed Thread