[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Emacs Lisp - Reading a sequence of bytes as one integer
From: |
Jeff Clough |
Subject: |
Re: Emacs Lisp - Reading a sequence of bytes as one integer |
Date: |
Sat, 13 Mar 2010 14:10:22 -0500 (EST) |
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