module BinaryParser::BinaryManipulateFunction
Constants
- MASK
Public Instance Methods
convert_uint_into_binary(uint, bit_length)
click to toggle source
# File lib/binary_parser/general_class/binary_manipulate_function.rb, line 38 def convert_uint_into_binary(uint, bit_length) if uint == 0 if bit_length > 0 convert_uint_into_binary(0, bit_length - 8) + [0].pack("C1") else [].pack("C0") end else convert_uint_into_binary(uint / 256, bit_length - 8) + [uint % 256].pack("C1") end end
convert_uint_into_binary_in_domain_of_definition?(uint, bit_length)
click to toggle source
# File lib/binary_parser/general_class/binary_manipulate_function.rb, line 50 def convert_uint_into_binary_in_domain_of_definition?(uint, bit_length) bit_length >= 0 && 0 <= uint && uint < 2 ** bit_length end
needed_sub_string(str, bit_first_pos, bit_last_pos)
click to toggle source
# File lib/binary_parser/general_class/binary_manipulate_function.rb, line 14 def needed_sub_string(str, bit_first_pos, bit_last_pos) return str[(bit_first_pos / 8)..(bit_last_pos / 8)], bit_first_pos % 8, 7 - (bit_last_pos % 8) end
needed_sub_string_in_domain_of_definition?(str, bfp, blp)
click to toggle source
# File lib/binary_parser/general_class/binary_manipulate_function.rb, line 18 def needed_sub_string_in_domain_of_definition?(str, bfp, blp) bfp < blp && blp / 8 < str.length end
to_unsigned_int(binary_string, margin_left=0, margin_right=0)
click to toggle source
# File lib/binary_parser/general_class/binary_manipulate_function.rb, line 22 def to_unsigned_int(binary_string, margin_left=0, margin_right=0) chars = binary_string.unpack("C*") converted = chars.shift & MASK[margin_left] chars.each do |char| converted = (converted << 8) + char end return converted >> margin_right end
to_unsigned_int_in_domain_of_definition?(str, ml, mr)
click to toggle source
# File lib/binary_parser/general_class/binary_manipulate_function.rb, line 31 def to_unsigned_int_in_domain_of_definition?(str, ml, mr) [ str.length >= 1, 0 <= ml && ml <= 7, 0 <= mr && mr <= 7, str.length != 1 || ml + mr <= 7 ].all? end