Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail From: Lew Newsgroups: comp.lang.java.programmer Subject: Re: Java left shift and right shift operators. Date: Tue, 26 Apr 2011 09:47:06 -0400 Organization: albasani.net Lines: 27 Message-ID: References: <295e16b3-2ed8-4529-bfb0-1cc26ed93ad6@d26g2000prn.googlegroups.com> <1b558330-ae94-4e4e-9922-a9aeb63eaf37@d19g2000prh.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net wA5Uxbus+008x2FNe7TH4FfM5BGZFUsoRnva+Zg5k8IbnB1d5AKlR/xu7GidEYlBhk+nJ7IMwK/o/BGMTmLBaqY9CWElAnsCDGUW3tes3AHZvbNWVJhZM5+2+QtJcc61 NNTP-Posting-Date: Tue, 26 Apr 2011 13:47:00 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="aR3gRtY6FZeRcLrQc1pIE84LZjk/d1Cgd+f6KlQK5Rd3awPP7SVjvhx50CQB33u+XDyL8jCOiZHGG3GG+Hvv6sVEjprn7UljI8VQQS3Pteb7kyekkmS8XlEBw/E6gi+9"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.14) Gecko/20110223 Thunderbird/3.1.8 In-Reply-To: Cancel-Lock: sha1:MBsO1tRYd7iF3nF1XeIO1kD81u8= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3260 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. Answer the questions people ask you, Sanny-Boy. -- Lew Honi soit qui mal y pense. http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg