From: noreply@... Date: 2006-10-25T22:59:37+09:00 Subject: [ ruby-Bugs-6314 ] Bitwise inversion of 32 bit numbers with most significant bit set results in overflow Bugs item #6314, was opened at 2006-10-25 08:59 You can respond by visiting: http://rubyforge.org/tracker/?func=detail&atid=1698&aid=6314&group_id=426 Category: Core Group: 1.9.x Status: Open Resolution: None Priority: 3 Submitted By: Ian Roddis (ian_roddis) Assigned to: Nobody (None) Summary: Bitwise inversion of 32 bit numbers with most significant bit set results in overflow Initial Comment: Tested using nightly snapshot and 1.8.5 stable: # ./ruby -v ruby 1.9.0 (2006-10-23) [i686-linux] #./ruby -e 'a= "7fffff00".hex ; b= "ffffff00".hex ; printf "%b => %b\n", a, ~a ; printf "%b => %b\n", b, ~b' 1111111111111111111111100000000 => ..10000000000000000000000011111111 11111111111111111111111100000000 => ..1 Case 1: A number with bit 32 (most significant) not set. No overflow. Case 2: A number with bit 32 set. Overflow observed. This may be caused by the right-shifting of a VALUE type (unsigned long) during the inversion process. Workaround: use XOR 0xffffffff instead. ---------------------------------------------------------------------- You can respond by visiting: http://rubyforge.org/tracker/?func=detail&atid=1698&aid=6314&group_id=426