From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jeff Clough Newsgroups: gmane.emacs.help Subject: Re: Emacs Lisp - Reading a sequence of bytes as one integer Date: Sat, 13 Mar 2010 14:10:22 -0500 (EST) Message-ID: <20100313.141022.80614820.jeff@chaosphere.com> References: <20100313.115617.104330838.jeff@chaosphere.com> <87hbokgn22.fsf@mithlond.arda> <20100313.131029.39330337.jeff@chaosphere.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1268507317 15126 80.91.229.12 (13 Mar 2010 19:08:37 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 13 Mar 2010 19:08:37 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Mar 13 20:08:33 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1NqWhG-0001gv-P7 for geh-help-gnu-emacs@m.gmane.org; Sat, 13 Mar 2010 20:08:27 +0100 Original-Received: from localhost ([127.0.0.1]:44653 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NqWhG-0003Zy-9A for geh-help-gnu-emacs@m.gmane.org; Sat, 13 Mar 2010 14:08:26 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NqWgA-00035k-O5 for help-gnu-emacs@gnu.org; Sat, 13 Mar 2010 14:07:18 -0500 Original-Received: from [140.186.70.92] (port=48936 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NqWg8-00034K-Lz for help-gnu-emacs@gnu.org; Sat, 13 Mar 2010 14:07:17 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NqWg6-0002vt-Dn for help-gnu-emacs@gnu.org; Sat, 13 Mar 2010 14:07:16 -0500 Original-Received: from hrndva-omtalb.mail.rr.com ([71.74.56.122]:56400) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NqWg6-0002vh-0g for help-gnu-emacs@gnu.org; Sat, 13 Mar 2010 14:07:14 -0500 X-Authority-Analysis: v=1.0 c=1 a=NZNNiAkOFsgA:10 a=kj9zAlcOel0A:10 a=O2KRN8bHAAAA:8 a=pPmEb8kHwpmWvvMMBycA:9 a=3zIGvnM0HCQ7R4uqu8QA:7 a=byjY5xbaO4S5Euz_F5qT0PUS6RYA:4 a=CjuIK1q_8ugA:10 a=-a4hDESKBCwA:10 X-Cloudmark-Score: 0 X-Originating-IP: 74.70.71.134 Original-Received: from [74.70.71.134] ([74.70.71.134:58823] helo=localhost) by hrndva-oedge03.mail.rr.com (envelope-from ) (ecelerity 2.2.2.39 r()) with ESMTP id 33/EB-01194-062EB9B4; Sat, 13 Mar 2010 19:07:13 +0000 In-Reply-To: <20100313.131029.39330337.jeff@chaosphere.com> X-Mailer: Mew version 6.3 on Emacs 23.1 / Mule 6.0 (HANACHIRUSATO) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:72420 Archived-At: From: Jeff Clough Date: Sat, 13 Mar 2010 13:10:29 -0500 (EST) > Is there some general way I can tell emacs "Take the three bytes > following point and make one integer out of them"? Well, I've managed to figure this out, although it's the "hard way". I grab the data as a string, then bust out each byte into its own character/integer and finally I do the math to convert it into an appropriate value. My quick and dirty mock-up... (defun decode-int (a-string) (+ (* (string-to-char (substring a-string 0 1)) 256 256) (* (string-to-char (substring a-string 1 2)) 256) (string-to-char (substring a-string 2 3)))) Still looking for a better way, but I'll put together a nicer version of the above later that will serve my particular purposes. Jeff