我想一次从STDIN连续读取四个字节,并以十六进制的形式输出。我试过使用读、读字节、each_byte,但我似乎无法让它工作。
cat file | ./processor.rb
0x...
0x...
...
其中文件是二进制文件。
发布于 2014-03-23 07:16:22
STDIN.each_byte.each_slice(4) { |b4|
# Do something with `b4`. `b4` is an array that contains up to 4 bytes
}
或
STDIN.each_char.each_slice(4) { |c4|
# Do something with `c4`. `c4` is an array that contains up to 4 characters
}
https://stackoverflow.com/questions/22592672
复制相似问题