X-FeedAbuse: http://nntpfeed.proxad.net/abuse.pl feeded by 88.191.16.109 Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!nospam.fr.eu.org!usenet-fr.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: Java left shift and right shift operators. Date: Tue, 26 Apr 2011 21:14:48 -0400 Organization: A noiseless patient Spider Lines: 50 Message-ID: References: <295e16b3-2ed8-4529-bfb0-1cc26ed93ad6@d26g2000prn.googlegroups.com> <1b558330-ae94-4e4e-9922-a9aeb63eaf37@d19g2000prh.googlegroups.com> <44bbc323-c260-4169-ab2a-11b95d9e73e8@34g2000pru.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 27 Apr 2011 01:15:26 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="KiwfXDyOjqGhZBXcfNnZBg"; logging-data="10918"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19cpQ7r2hujxZUS+dPaMoLU" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 In-Reply-To: <44bbc323-c260-4169-ab2a-11b95d9e73e8@34g2000pru.googlegroups.com> Cancel-Lock: sha1:vN7y0KaqJcF25CJ9HI7rv8yJvs8= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3290 On 4/26/2011 12:39 PM, 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? > > I didnt knew how much inefficient it is. I heard Math. (...) functions > are very fast and they use Native support like assembly language so > they are quite faster. "Fast" is not an absolute, and neither is "very fast." If you plant an acorn today and have a fifty-foot oak tree in ten years, that's "fast." If you strike a match now and see a flame in ten minutes, that's "slow" even though its half a million times faster than the "fast" oak tree. In other words, interpret "fast" in relation to the amount of work being done. > Is there a "Integer" in java which is longer than 64 bits? > [...] > I have heard of BigInteger I dont know how many bits it supports. Perhaps the Javadoc for BigInteger might be helpful? Oh, no, sorry, that's *way* too obvious, there must be a grue waiting for anyone who tries to read the Javadoc. Never mind. > Can I use byte[] to represent a longer number and do multiplications/ > divisions on them? No. Somebody else could, if he were sufficiently masochistic, but at your present level of Java proficiency[*] it's pretty clear that you cannot. [*] No offense: We all begin from ignorance. Your progress from the starting point is not yet enough to enable you to do this task. -- Eric Sosman esosman@ieee-dot-org.invalid