From: John Joyce Date: 2007-06-18T05:01:56+09:00 Subject: Re: wite an integer to file as binary On Jun 17, 2007, at 2:36 PM, Rick DeNatale wrote: > On 6/15/07, John Joyce 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.