Method: Integer#invert

Defined in:
lib/epitools/core_ext/numbers.rb

#invertObject

Flip all bits except the sign bit.

NOTE: This method should only be used with unsigned integers; if you use it with a signed integer, it will only flip the non-sign bits (I dunno if that’s useful for anything; nothing comes to mind.)



404
405
406
# File 'lib/epitools/core_ext/numbers.rb', line 404

def invert
  to_s(2).tr("01","10").to_i(2)
end