I am trying to convert unpacked value of 4 byte array? Is this possible in Ruby?
say I wrote b1 = b.unpack("N")
and print value of b1
which is 1
. But when I try to convert b1 to some integer using .to_i console throws error test.rb:13: undefined method
to_i' for [118]:Array (NoMethodError)`
My code is following:
File.open('testfile','rb') do |file|
file.read.scan(/(.{4})(.{4})(.{4})(.*\w)(.{8})/).each do |a,b,c,d,e|
if a == "cook"
puts "test1"
else
puts "test2"
end
puts "output1"
b1 = b.unpack("N")
puts "output2"
c1 = c.unpack("N")
puts "output3"
puts "output4"
puts "output5"
end
end