all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Andreas Politz <politza@fh-trier.de>
To: help-gnu-emacs@gnu.org
Subject: Re: Emacs Lisp - Reading a sequence of bytes as one integer
Date: Sun, 14 Mar 2010 09:03:22 +0100	[thread overview]
Message-ID: <87wrxf8h4l.fsf@fh-trier.de> (raw)
In-Reply-To: 20100313.141022.80614820.jeff@chaosphere.com

Jeff Clough <jeff@chaosphere.com> writes:

> From: Jeff Clough <jeff@chaosphere.com>
> 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





  reply	other threads:[~2010-03-14  8:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-13 16:56 Emacs Lisp - Reading a sequence of bytes as one integer Jeff Clough
2010-03-13 17:15 ` Teemu Likonen
2010-03-13 18:10   ` Jeff Clough
2010-03-13 19:10     ` Jeff Clough
2010-03-14  8:03       ` Andreas Politz [this message]
2010-03-13 19:42     ` Teemu Likonen
2010-03-13 18:49 ` Eli Zaretskii
2010-03-13 19:12   ` Jeff Clough

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wrxf8h4l.fsf@fh-trier.de \
    --to=politza@fh-trier.de \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.