Module: Bitindex::Common
Constant Summary collapse
- SIGNED_16BIT =
2**15 / 8
- UNSIGNED_16BIT =
2**16 / 8
- SIGNED_32BIT =
2**31 / 8
- UNSIGNED_32BIT =
2**32 / 8
Instance Method Summary collapse
- #bit_set?(byte, value, ltor = true) ⇒ Boolean
- #build_mask(value, ltor = true) ⇒ Object
- #byte_pos(value) ⇒ Object
- #set_bit(byte, value, ltor = true) ⇒ Object
- #unset_bit(byte, value, ltor = true) ⇒ Object
Instance Method Details
#bit_set?(byte, value, ltor = true) ⇒ Boolean
10 11 12 13 |
# File 'lib/bitindex/common.rb', line 10 def bit_set? byte, value, ltor = true mask = build_mask value, ltor (byte & mask) != 0 end |
#build_mask(value, ltor = true) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/bitindex/common.rb', line 30 def build_mask value, ltor = true shift = value & 0x07 if ltor (0x80 >> shift) else (0x01 << shift) end end |
#byte_pos(value) ⇒ Object
26 27 28 |
# File 'lib/bitindex/common.rb', line 26 def byte_pos value (value >> 3) end |
#set_bit(byte, value, ltor = true) ⇒ Object
15 16 17 18 |
# File 'lib/bitindex/common.rb', line 15 def set_bit byte, value, ltor = true mask = build_mask value, ltor (byte | mask) end |
#unset_bit(byte, value, ltor = true) ⇒ Object
20 21 22 23 24 |
# File 'lib/bitindex/common.rb', line 20 def unset_bit byte, value, ltor = true mask = build_mask value, ltor mask ^= 0xff (byte & mask) end |