From ... Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!lnsnews.lns.cornell.edu!news.cse.sc.edu!news.stealth.net!news.stealth.net!uio.no!nntp.uio.no!ifi.uio.no!not-for-mail From: Erik Naggum Newsgroups: comp.lang.lisp Subject: Re: Q: How to write binary data to a file? Date: 03 Sep 2002 20:31:42 +0000 Organization: Naggum Software, Oslo, Norway Lines: 34 Message-ID: <3240073902064268@naggum.no> References: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: maud.ifi.uio.no 1031085103 21753 129.240.64.16 (3 Sep 2002 20:31:43 GMT) X-Complaints-To: abuse@ifi.uio.no NNTP-Posting-Date: 3 Sep 2002 20:31:43 GMT Mail-Copies-To: never User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: archiver1.google.com comp.lang.lisp:39547 * Ryan M. Rifkin | I'm a (relative) Lisp newbie, trying to learn. I'm interested in writing | integers to a file as 16-bit signed integers. (The integers I need to write | will fit in this representation. I am writing audio data to the file, which | is why I need to output in a binary format). Just specify `:element-type ' (signed-byte 16)´ and go ahead and `write-byte´ values in the appropriate range to the stream. | I'm aware of the function write-byte, but I'm not sure how to write my | signed integers. `write-byte´ does not write IBMese 8-bit bytes, but real bytes, contiguous sequences of bits in an integer. In the words of the Common Lisp Glossary: byte n. 1. adjacent bits within an integer. (The specific number of bits can vary from point to point in the program; see the function `byte´.) 2. an integer in a specified range. (The specific range can vary from point to point in the program; see the functions `open´ and `write-byte´.) This definition of "byte" predates the IBM abuse of the term and comes from the PDP-6 and -10 hardware designs, which were 36-bit word machines, meaning the smallest addressable unit was one machine word of 36 bits. I believe IBM invented the byte-addressable hardware. Your main confusion comes from thinking that "byte" means the same thing in Common Lisp as it means in, say, C. -- Erik Naggum, Oslo, Norway Act from reason, and failure makes you rethink and study harder. Act from faith, and failure makes you blame someone and push harder.