help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Emacs Lisp - Reading a sequence of bytes as one integer


From: Andreas Politz
Subject: Re: Emacs Lisp - Reading a sequence of bytes as one integer
Date: Sun, 14 Mar 2010 09:03:22 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

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 via email to

[Prev in Thread] Current Thread [Next in Thread]