Solved

the << operator

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Android studio getdrawable(int) is deprecated 4 83
sites similar to codingbat to improve coding hanson skills 3 49
hibernate example using maven 12 41
jsp login check 12 30
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

776 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