Skip to content

Instantly share code, notes, and snippets.

@wulftone
Created October 5, 2011 22:22
Show Gist options
  • Save wulftone/1265920 to your computer and use it in GitHub Desktop.
Save wulftone/1265920 to your computer and use it in GitHub Desktop.
Extending String and Array with bitmask helpers
# Convert a number in a string to a different base (stolen from stackoverflow.com)
class String
def convert_base(from, to)
self.to_i(from).to_s(to)
end
end
# Convert an array to it's maximum value if it were representing binary and filled with 1's
class Array
def max_bitmask
self.map{1}.join().convert_base(2,10).to_i
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment