lib/bindata/int.rb in bindata-2.3.3 vs lib/bindata/int.rb in bindata-2.3.4

- old
+ new

@@ -94,14 +94,14 @@ end def create_read_assemble_code(nbits, endian, signed) nwords = nbits / bits_per_word(nbits) - idx = (0 ... nwords).to_a - idx.reverse! if (endian == :big) + idx = (0...nwords).to_a + idx.reverse! if endian == :big - parts = (0 ... nwords).collect do |i| + parts = (0...nwords).collect do |i| "(ints.at(#{idx[i]}) << #{bits_per_word(nbits) * i})" end parts[0].sub!(/ << 0\b/, "") # Remove " << 0" for optimisation parts.join(" + ") @@ -124,11 +124,11 @@ def val_as_packed_words(nbits, endian, signed) nwords = nbits / bits_per_word(nbits) mask = (1 << bits_per_word(nbits)) - 1 - vals = (0 ... nwords).collect { |i| "val >> #{bits_per_word(nbits) * i}" } + vals = (0...nwords).collect { |i| "val >> #{bits_per_word(nbits) * i}" } vals[0].sub!(/ >> 0\b/, "") # Remove " >> 0" for optimisation vals.reverse! if (endian == :big) vals = vals.collect { |val| "#{val} & #{mask}" } # TODO: "& mask" is needed to work around jruby bug. Remove this line when fixed. vals.join(",") @@ -155,18 +155,18 @@ directives = { 8 => "C", 16 => "S", 32 => "L", 64 => "Q" } d = directives[bits_per_word(nbits)] d << ((endian == :big) ? ">" : "<") unless d == "C" - if signed == :signed and directives.has_key?(nbits) + if signed == :signed && directives.key?(nbits) (d * nwords).downcase else d * nwords end end def need_signed_conversion_code?(nbits, signed) - signed == :signed and not [64, 32, 16].include?(nbits) + signed == :signed && ![64, 32, 16].include?(nbits) end end end