Solved

the << operator

Posted on 2006-10-22
4
253 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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Protect jar file - windows app 2 65
custom annotations 9 42
object oriented programming comparison 5 77
American Express @Work site and Java 4 18
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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.

809 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