Simple Sand Samples |
Ruby > バイナリファイルを読み込む
read-bin.rb
f = open(ARGV[0], "rb") f.each_byte do |c| printf"%02X ",c end puts"" f.close
$ echo -ne "\x1\x2\x3" > hoge.bin
$ od -tx1 hoge.bin
0000000 01 02 03
0000003
$ ruby read-bin.rb hoge.bin
01 02 03
$
$ od -tx1 hoge.bin
0000000 01 02 03
0000003
$ ruby read-bin.rb hoge.bin
01 02 03
$
* 確認環境 Debian Linux(Wheezy)