gpt4 book ai didi

ruby - 包 ('L' 的奇怪行为)

转载 作者:太空宇宙 更新时间:2023-11-03 17:55:33 24 4
gpt4 key购买 nike

如果我尝试使用 pack('L') 将压缩字节作为无符号 int32 写入文件,数字 10 将写入五个字节。使用任何其他数字我都会得到正常的行为。

我写了一个简单的脚本:

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

并得到 this result ;查看第 10 次迭代。

我的错误在哪里?

Ruby 版本:ruby 1.9.3p327 (2012-11-10) [i386-mingw32]

最佳答案

这是一个换行符转换问题(特定于 Windows):字节 10 被转换为 CR+LF。

我不懂 ruby​​,但是 openwb 而不是 w 可能会有帮助。

关于ruby - 包 ('L' 的奇怪行为),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14508383/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com