Solved

the << operator

Posted on 2006-10-22
4
226 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
4 Comments
 
LVL 92

Accepted Solution

by:
objects earned 25 total points
Comment Utility
0
 
LVL 2

Assisted Solution

by:avsrivastava
avsrivastava earned 25 total points
Comment Utility
>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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
allStar challenge 1 40
strDist challenge 35 84
Understanding websocket example in spring 1 41
topping1 challenge 7 47
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 …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
The viewer will learn how to implement Singleton Design Pattern in Java.
This video teaches viewers about errors in exception handling.

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now