From: Jim Weirich Date: 2006-04-09T05:52:51+09:00 Subject: Re: Ruby: shift right operator (>>) does not work correctly Vitalie Lazu wrote: > It seems to be a bug with >> operator: > > 4653896912 >> 13 should be 43814 like it is in java or php, but not > 568102. > > Tested with ruby 1.8.2 in windows xp and freebsd. > > any related issues to this subject? > > Best regards, > Vitalie > Math.log(4653896912) / Math.log(2) => 32.1157921080915 There you have it, the number 4653896912 cannot be represented in 32 bits (it needs 33 bits, 34 if you add a sign bit). Java is truncating the value: > (4653896912 & 0xffffffff) => 358929616 > 358929616 >> 13 => 43814 -- Jim Weirich -- Posted via http://www.ruby-forum.com/.