From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andreas Politz Newsgroups: gmane.emacs.help Subject: Re: Emacs Lisp - Reading a sequence of bytes as one integer Date: Sun, 14 Mar 2010 09:03:22 +0100 Message-ID: <87wrxf8h4l.fsf@fh-trier.de> References: <20100313.115617.104330838.jeff@chaosphere.com> <87hbokgn22.fsf@mithlond.arda> <20100313.131029.39330337.jeff@chaosphere.com> <20100313.141022.80614820.jeff@chaosphere.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1268554254 5181 80.91.229.12 (14 Mar 2010 08:10:54 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 14 Mar 2010 08:10:54 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Mar 14 09:10:48 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 1NqiuO-000882-6K for geh-help-gnu-emacs@m.gmane.org; Sun, 14 Mar 2010 09:10:48 +0100 Original-Received: from localhost ([127.0.0.1]:54549 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NqiuM-00030M-63 for geh-help-gnu-emacs@m.gmane.org; Sun, 14 Mar 2010 04:10:46 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NqinZ-0002FR-B4 for help-gnu-emacs@gnu.org; Sun, 14 Mar 2010 04:03:45 -0400 Original-Received: from [140.186.70.92] (port=37838 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NqinW-0002Eg-L9 for help-gnu-emacs@gnu.org; Sun, 14 Mar 2010 04:03:43 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NqinU-0002O2-Hj for help-gnu-emacs@gnu.org; Sun, 14 Mar 2010 04:03:42 -0400 Original-Received: from lo.gmane.org ([80.91.229.12]:51753) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NqinU-0002Nj-9r for help-gnu-emacs@gnu.org; Sun, 14 Mar 2010 04:03:40 -0400 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1NqinR-0005jR-Bg for help-gnu-emacs@gnu.org; Sun, 14 Mar 2010 09:03:37 +0100 Original-Received: from dslb-088-068-211-046.pools.arcor-ip.net ([88.68.211.46]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 14 Mar 2010 09:03:37 +0100 Original-Received: from politza by dslb-088-068-211-046.pools.arcor-ip.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 14 Mar 2010 09:03:37 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 26 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: dslb-088-068-211-046.pools.arcor-ip.net User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:gj9XZFC1K1dn5OOkhVjxk9g299k= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) 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:72428 Archived-At: Jeff Clough writes: > 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 string-to-list/get-byte , logior and lsh might come in handy. -ap