473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 48269
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: serge calderara | last post by:
Dear all, I would like toi understand clearly what does that tag <Serialiaze> reaaly means and when to use it and how? I have seen it in many places thanks for your answer regards serge
2
by: Steve Richter | last post by:
What does the "." mean in the following sql script stmts? use GO if exists (select * from dbo.sysobjects where id = object_id(N'.') and OBJECTPROPERTY(id,N'IsUserTable') = 1) drop table ....
3
by: RobertTG | last post by:
Someone please translate the code below into English... Particularly the indicated line Thanks function attachComment() { var aForms = document.getElementsByTagName("FORM"); for (var i = 0;...
6
by: allenj | last post by:
DB21085I Instance "md" uses "32" bits and DB2 code release "SQL08012" with level identifier "02030106". Informational tokens are "DB2 v8.1.0.16", "s030508", "MI00048", and FixPak "2". Product is...
58
by: Larry David | last post by:
Ok, first of all, let's get the obvious stuff out of the way. I'm an idiot. So please indulge me for a moment. Consider it an act of "community service".... What does "64bit" mean to your friendly...
92
by: Heinrich Pumpernickel | last post by:
what does this warning mean ? #include <stdio.h> int main() { long l = 100; printf("l is %li\n", l * 10L);
45
by: loudking | last post by:
Hello, all I don't quite understand what does ((time_t)-1) mean when I execute "man 2 time" RETURN VALUE On success, the value of time in seconds since the Epoch is retu rned. On error,...
1
by: mysticwater | last post by:
Hi, I have a question related to c++ syntax. I was looking at c++ code and I noticed that a lot of the times notation in the following format (with different names of course) Box<Object>. An...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.