Si j'essaie d'écrire un octet compressé en tant qu'int32 non signé dans un fichier, en utilisant pack('L')
, le nombre 10
écrit comme cinq octets. Avec n'importe quel autre numéro, j'ai le comportement normal.Comportement étrange avec pack ('L')
j'ai écrit script simple:
x = 0
while x < 100 do
puts "\nTesting %s..." % [x]
h = [x].pack('L')
puts "h length: %s" % [h.length]
f = File.open('tmp', 'w')
f.write h
puts "position: %s" % [f.pos]
x += 1
end
et obtenir this result; Regardez le numéro d'itération 10.
Où est mon erreur?
Version Rubis: Rubis 1.9.3p327 (10/11/2012) [i386-mingw32]
Exécution de votre extrait sur 'ruby 1.9.3p125 (2012-02-16 révision 34643) [x86_64-darwin12.1.0]' Je reçois '4' octets tout le long :( – Nevir