Solved

the << operator

Posted on 2006-10-22
4
265 Views
Last Modified: 2010-03-31
Hi,
   What is the << operator?  such as
   x = (y << 1);
  Is there an equivalent way of expressing it? like in if/else/other operators statements?
0
Comment
Question by:azcalv408
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 92

Accepted Solution

by:
objects earned 25 total points
ID: 17785875
0
 
LVL 2

Assisted Solution

by:avsrivastava
avsrivastava earned 25 total points
ID: 17786311
>Is there an equivalent way of expressing it?
a left shift by 1(<<1) is equivalent to multiplication by 2.
a left shift by n is same as multiplication by 2^n(2 raised to the power n).

similarly a right shift by n(>>n) is same as division by 2^n.

so, x = (y<<1);
is same as x = y*2;
but the shift is a  faster operation than multiplication, and hence usually preferred (only useful when multiplying by powers of 2 though).
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question