473,396 Members | 2,098 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,396 software developers and data experts.

operator

Expand|Select|Wrap|Line Numbers
  1. cout <<  30 << 3 ;

What operator "<<" is that ? i mean the one in between 30 and 3...
and what is the difference between "<", "<<", ">", ">>" ?
thx in advance...
Apr 29 '07 #1
5 1228
Expand|Select|Wrap|Line Numbers
  1. int f()
  2. {    int a =10,b=10;
  3.     if(a==b)
  4.     {
  5.                     a*=3;
  6.     }
  7.     a = a << 2;
  8.     return a;
  9. }
  10.  
  11. void main()
  12. {cout<<f();}
  13.  
  14.  
I posted the wrong question, this is the original question, what does the operator in a "<<" 2 suppose to mean? and what it is called ?
Apr 29 '07 #2
ilikepython
844 Expert 512MB
Expand|Select|Wrap|Line Numbers
  1. int f()
  2. {    int a =10,b=10;
  3.     if(a==b)
  4.     {
  5.                     a*=3;
  6.     }
  7.     a = a << 2;
  8.     return a;
  9. }
  10.  
  11. void main()
  12. {cout<<f();}
  13.  
  14.  
I posted the wrong question, this is the original question, what does the operator in a "<<" 2 suppose to mean? and what it is called ?
The "<<" is a bit shift operator. It shifts the binary "1"s and "0"s by the number after it.
So for example:
in your case a = 30
the binary bits for that is:
00011110
so if you shift the bits 2 times you get:
01111000
notice how the "1"s shifted to the left, that makes "a" equal 120
Expand|Select|Wrap|Line Numbers
  1. 128 64 32 16       8 4 2 1
  2. ------------------------------------
  3. 0   1  1  1        1 0 0 0
  4. 0 +64+32+16  +     8+0+0+0 = 120
  5.  
Does that help?
Apr 29 '07 #3
The "<<" is a bit shift operator. It shifts the binary "1"s and "0"s by the number after it.
So for example:
in your case a = 30
the binary bits for that is:
00011110
so if you shift the bits 2 times you get:
01111000
notice how the "1"s shifted to the left, that makes "a" equal 120
Expand|Select|Wrap|Line Numbers
  1. 128 64 32 16       8 4 2 1
  2. ------------------------------------
  3. 0   1  1  1        1 0 0 0
  4. 0 +64+32+16  +     8+0+0+0 = 120
  5.  
Does that help?

sorry late reply, I lost the url to the forum...

Hah! thanks, really helps especially on the conversion table! NEAT!

But i hv another question....
I changed the shift operator from "<<" to this "<"
there's no error upon compilation, i tried to search "<" under the shift operator but no answer... you know what's that?
May 4 '07 #4
Ganon11
3,652 Expert 2GB
While "<<" is a bit shift operator, "<" does something completely different. "<" is the "less than" operator. It evaluates to true (i.e. a nonzero integer, usually 1) is the left hand side is less than the right hand side, and false (i.e. 0) if the right hand side is less than or equal to the left hand side. So your code

Expand|Select|Wrap|Line Numbers
  1. a = a < 3;
will assign 1 to a if a was originally less than 3, or 0 to a otherwise.
May 4 '07 #5
While "<<" is a bit shift operator, "<" does something completely different. "<" is the "less than" operator. It evaluates to true (i.e. a nonzero integer, usually 1) is the left hand side is less than the right hand side, and false (i.e. 0) if the right hand side is less than or equal to the left hand side. So your code

Expand|Select|Wrap|Line Numbers
  1. a = a < 3;
will assign 1 to a if a was originally less than 3, or 0 to a otherwise.
Thanks! I got all the operators mixed up!
May 5 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Paul Davis | last post by:
I'd like to overload 'comma' to define a concatenation operator for integer-like classes. I've got some first ideas, but I'd appreciate a sanity check. The concatenation operator needs to so...
1
by: joesoap | last post by:
Hi can anybody please tell me what is wrong with my ostream operator??? this is the output i get using the 3 attached files. this is the output after i run assignment2 -joesoap #include...
5
by: Jason | last post by:
Hello. I am trying to learn how operator overloading works so I wrote a simple class to help me practice. I understand the basic opertoar overload like + - / *, but when I try to overload more...
0
by: Martin Magnusson | last post by:
I have defined a number of custom stream buffers with corresponding in and out streams for IO operations in my program, such as IO::output, IO::warning and IO::debug. Now, the debug stream should...
3
by: Sensei | last post by:
Hi. I have a problem with a C++ code I can't resolve, or better, I can't see what the problem should be! Here's an excerpt of the incriminated code: === bspalgo.cpp // THAT'S THE BAD...
6
by: YUY0x7 | last post by:
Hi, I am having a bit of trouble with a specialization of operator<<. Here goes: class MyStream { }; template <typename T> MyStream& operator<<(MyStream& lhs, T const &)
3
by: gugdias | last post by:
I'm coding a simple matrix class, which is resulting in the following error when compiling with g++ 3.4.2 (mingw-special): * declaration of `operator/' as non-function * expected `;' before '<'...
5
by: raylopez99 | last post by:
I need an example of a managed overloaded assignment operator for a reference class, so I can equate two classes A1 and A2, say called ARefClass, in this manner: A1=A2;. For some strange reason...
8
by: valerij | last post by:
Yes, hi How to write "operator +" and "operator =" functions in a class with a defined constructor? The following code demonstrates that I don't really understand how to do it... I think it has...
3
by: y-man | last post by:
Hi, I am trying to get an overloaded operator to work inside the class it works on. The situation is something like this: main.cc: #include "object.hh" #include "somefile.hh" object obj,...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
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...

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.