Module: Ronin::Support::Binary::BitFlip::Integer
- Defined in:
- lib/ronin/support/binary/bit_flip.rb
Overview
Methods for bit-flipping Integers.
Class Method Summary collapse
-
.bit_flips(int, bits) ⇒ Array<Integer>
Returns every bit flip in the integer.
-
.each_bit_flip(int, bits) {|int| ... } ⇒ Enumerator
Enumerates over every bit flip in the integer.
Class Method Details
.bit_flips(int, bits) ⇒ Array<Integer>
Returns every bit flip in the integer.
102 103 104 |
# File 'lib/ronin/support/binary/bit_flip.rb', line 102 def self.bit_flips(int,bits) each_bit_flip(int,bits).to_a end |
.each_bit_flip(int, bits) {|int| ... } ⇒ Enumerator
Enumerates over every bit flip in the integer.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/ronin/support/binary/bit_flip.rb', line 65 def self.each_bit_flip(int,bits,&block) return enum_for(__method__,int,bits) unless block_given? bits = case bits when ::Range then bits when ::Integer then (0...bits) else raise(ArgumentError,"bits must be an Integer or a Range: #{bits.inspect}") end bits.each do |bit_index| mask = 1 << bit_index yield int ^ mask end end |