Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx02.iad01.newshosting.com!209.197.12.242.MISMATCH!nx01.iad01.newshosting.com!newshosting.com!news-out.readnews.com!transit3.readnews.com!postnews.google.com!d19g2000prh.googlegroups.com!not-for-mail From: Sanny Newsgroups: comp.lang.java.programmer Subject: Re: Java left shift and right shift operators. Date: Tue, 26 Apr 2011 02:04:23 -0700 (PDT) Organization: http://groups.google.com Lines: 39 Message-ID: <1b558330-ae94-4e4e-9922-a9aeb63eaf37@d19g2000prh.googlegroups.com> References: <295e16b3-2ed8-4529-bfb0-1cc26ed93ad6@d26g2000prn.googlegroups.com> NNTP-Posting-Host: 122.168.149.162 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1303808664 10465 127.0.0.1 (26 Apr 2011 09:04:24 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 26 Apr 2011 09:04:24 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: d19g2000prh.googlegroups.com; posting-host=122.168.149.162; posting-account=TwCTWQgAAAC7hf6GV7aTGIk6mVGkiZ5c User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; FDM),gzip(gfe) Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3254 > 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; This works for most cases but failed when output is greater than 9223372036854775807 N="9223372036854775807"; and shift by (-3); long output=(long)(9223372036854775807 / 0.125); The answer is "-1"; binary Value: 111111111111111111111111111111111111111111111111111111111111111 While correct answer is : 1000000000000000000000000000000000000000000000000000000000000000 It is because "long" is 64 bit signed variable. Can I get unsigned Long? Or bigger than long variable? So that 64 bit shifts can be done easily? Bye Sanny Java Experts needed http://www.GetClub.com/Experts.php [Lots of coding jobs to choose]