Path: csiph.com!x330-a1.tempe.blueboxinc.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: Wed, 27 Apr 2011 11:23:15 -0500 Date: Wed, 27 Apr 2011 09:23:08 -0700 From: Patricia Shanahan User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; 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> <1b558330-ae94-4e4e-9922-a9aeb63eaf37@d19g2000prh.googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Lines: 32 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 75.8.126.96 X-Trace: sv3-IKcsGwWxTEGoCO6wflnvdrVohg/DeITvE6iMvedOTY8up9Mh+bYAY2BjaLk+6TEG7dJs/iGDPRA6lH1!pIvoRDMuFTqZfyf44WtHwat9p5KtTfaULwUkYk0D4Q/60Pm4uXUbn9ZIQiiYJMlpK/RCrnn/Z8co!FOd7N4qdzYlRkOFnNDwGyshryDtFWUqM68hPOcEtHl8= 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: 2664 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3306 On 4/26/2011 6:47 AM, Lew wrote: > On 04/26/2011 07:34 AM, Eric Sosman wrote: >> On 4/26/2011 5:04 AM, Sanny wrote: >>>> Is there any way to avoid the if condition and do right shift and left >>>> shift using operators depending on shiftby is +ve or -ve? >>> >>> I used below technique but it gives error. >>> >>> divider=Math.pow(2,shiftby); >>> then >>> output = (long) N / divider; >> >> Let me get this straight: You're worried about the inefficiency >> of an `if' that chooses between a left or a right shift, so you plan >> to eliminate the `if' by evaluating an exponential function? >> >> ARE YOU OUT OF YOUR MIND? > > Especially given that shift is blazingly efficient on just about any > computer that supports Java. You're optimizing something that's used > *as* an optimization, Sanny-Boy. As far as I can tell, Lew-Boy, he has not asked to optimize out the shift, except as a means to the end of avoiding a conditional branch. Whether that is an issue or not depends on the context, the predictability of the branch, and the performance of the alternatives. [I had not previously seen appending "-Boy" to the name as a convention for addressing people in USENET articles, but I'll go along with whatever mode of address the person I'm responding to seems to prefer.] Patricia