From: Robert Klemme Date: 2008-06-14T21:59:20+09:00 Subject: Re: Binary string packing/unpacking issues On 14.06.2008 13:56, Lucas L. wrote: > Dave Bass wrote: >> "Pixels".each_byte { |b| printf("%08b\n", b) } > > That's good for the first problem, thanks. > Now for the more difficult one of efficiently manipulating small > portions of the packed binary data. With Ruby 1.8 you can easily manipulate individual bytes directly: irb(main):006:0> s="abc" => "abc" irb(main):007:0> s[2] => 99 irb(main):008:0> s[2].to_s 2 => "1100011" irb(main):009:0> s[2] |= 4 => 103 irb(main):010:0> s => "abg" irb(main):011:0> s[2].to_s 2 => "1100111" I don't have a 1.9 handy so I can't tell you how to do it there. But the basic lesson should be, that you can leave your data in a String and manipulate it directly there. Kind regards robert