Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Tue, 26 Apr 2011 05:16:50 -0500 Date: Tue, 26 Apr 2011 03:16:45 -0700 From: Patricia Shanahan User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Java left shift and right shift operators. References: <295e16b3-2ed8-4529-bfb0-1cc26ed93ad6@d26g2000prn.googlegroups.com> <188cz6ta97kkm$.dlg@kimmeringer.de> In-Reply-To: <188cz6ta97kkm$.dlg@kimmeringer.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Lines: 25 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 75.8.126.96 X-Trace: sv3-OqYkv1Q4JHpJUBfmyRLDFSe1lr2990X5OS0JsDSAWymueGbJ7ARje/rDAIogqqA234tDt3AjHCXnHmz!9vY7siVJKyU0n94gHeKV2/3vpHfNvK0l/ghUTitIvtjagxhRplsTrH3E0zqwicBNHlSs2V5B1hc+!SiwwgNKFqpat0fx0RugbMIKkm117MQEIBZpB1aFffRE= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2143 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3256 On 4/26/2011 12:55 AM, Lothar Kimmeringer wrote: > Sanny wrote: > >> I have a problem where I have to do left shift and right shift. >> > [...] >> >> I have to use use left shift and right shift to shift Number right/ >> left depending on value of shiftby >> >> if (shift>0) output = N>> shiftby; else output = N<< (-shiftby);// >> working but inefficient. > > In what way is it inefficient? Have you performed measurements > or do you simply think that it's slow and want to optimize > it prematurely? It is very important that the measurement be done in context, using the pattern of left and right shifts that occur in the real program. The very worst possible case is the one that many people might use in a test program, a random, equal probability, mix of left and right shifts. That makes the hardware branch prediction no better than random. Patricia