From: Jeff Clough <jeff@chaosphere.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Emacs Lisp - Reading a sequence of bytes as one integer
Date: Sat, 13 Mar 2010 14:10:22 -0500 (EST) [thread overview]
Message-ID: <20100313.141022.80614820.jeff@chaosphere.com> (raw)
In-Reply-To: <20100313.131029.39330337.jeff@chaosphere.com>
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
next prev parent reply other threads:[~2010-03-13 19:10 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 [this message]
2010-03-14 8:03 ` Andreas Politz
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100313.141022.80614820.jeff@chaosphere.com \
--to=jeff@chaosphere.com \
--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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).