473,486 Members | 2,394 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 48290
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
3290
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
10192
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
6636
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
22872
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
30155
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
6110
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
9289
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
1750
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
7105
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
7132
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,...
1
6846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5439
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4870
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
4564
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
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1381
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
266
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.