473,836 Members | 2,340 Online
Bytes | Software Development & Data Engineering Community
+ 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 48351
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.ca wrote 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.comwr ote in message
news:11******** *************@m 73g2000cwd.goog legroups.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.comwr ote in message
news:11******** *************@m 73g2000cwd.goog legroups.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

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

Similar topics

2
3318
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
10225
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 . GO
3
6660
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; i < aForms.length; i++) {
6
22942
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 installed at "/opt/IBM/db2/V8.1". Red Hat AS -------------------------------- what does this error mean? SQL Error Code -443, SQL State 38553, Routine "SYSIBM.SQLCOLUMNS"
58
30266
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 neighborhood C# programmer? The standard answer I get from computer sales people is: "It means that the CPU can process 64 bits of data at a time instead of 32." Ok... I guess I *kind* of understand what that means at an intuitive level, but what...
92
6272
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
9462
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, ((time_t)-1) is returned, and errno is set
1
1776
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 example of such syntax is seen below too: template <typename Object> class Box_tester:public Tester< Box<Object> > { using Tester< Box<Object> >::object; using Tester< Box<Object> >::command; public:
0
9810
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
10821
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10527
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10573
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10241
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6973
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5642
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5812
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4443
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 we have to send another system

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.