From: Jeff de Vries Date: 2002-11-23T07:09:01+09:00 Subject: Reading and writing binary data from files I just started reading about Ruby, and decided to try to use it to write a utility I need. One of the things that I need to do is to read a file that contains binary data (32-bit integers, and strings consisting of a 16-bit integer count followed by that many 8-bit chars) created from a C program. Poking around, I saw the sysread and syswrite calls, which appear to let me read 4 bytes (for a 32-bit integer, for example) into a string. The question is, short of picking each byte off one-by-one and doing the shift-add thing to build up an integer, can I just say "reinterpret this memory as an integer"? I also need to go the other way, writing out binary 32-bit integers. Thanks! Jeff