John Joyce
6/17/2007 8:02:00 PM
On Jun 17, 2007, at 2:36 PM, Rick DeNatale wrote:
> On 6/15/07, John Joyce <dangerwillrobinsondanger@gmail.com> wrote:
>> This one is always a stumper.
>> use the method to_s(2)
>> 5.to_s(2)
>> Converts 5 to base 2 (binary) as a string.
>> This is fine for output to a file!
>
> Except that the OP was looking to write the integer as 4 binary bytes.
> Array#pack is the way to go.
Oops! I missed the part about 4 binary bytes. Sometimes the inbox is
overflowing and read too fast...
>> Alternatively, if you're looking to set binary write mode for Windows
>> (versus text mode. this is windows only)
>> there is binmode
>
> That doesn't afffect how data is written, it keeps windows from
> processing control characters and doing things like prematurely giving
> an end-of-file if the data contains a ctrl-D character.
Someday, Windows will be another unix clone.