🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.help
Article #1798

Re: hexlify-buffer

#1798
From: Rick Sladkey
Date: Wed, 18 Nov 1992 02:22
57 lines
2365 bytes
>>>>> On 13 Nov 92 12:22:00 GMT, pot@fly.cnuce.cnr.it (Francesco
>>>>> Potorti`) said:

Francesco> Again, anyone able to make it faster?

I was also experimenting with hexlify-buffer and ended up doing it
this way.  On my system it is about six times faster than the original
and about twice as fast as Francesco's version.
-----
(defvar char-to-hex-vector (make-vector 256 nil)
  "Vector of hex string equivalents of characters.")

(let ((i 0))
  (while (< i 256)
    (aset char-to-hex-vector i (format "%02x" i))
    (setq i (1+ i))))

(defvar char-to-prt-vector (make-vector 256 nil)
  "Vector of printable string equivalents of characters.")

(let ((i 0))
  (while (< i 256)
    (aset char-to-prt-vector i
	  (format "%c" (if (or (< i 32) (>= i 127)) 46 i)))
    (setq i (1+ i))))

(defun hexlify-buffer ()
  "Convert a binary buffer to hexl format"
  (interactive)
  (goto-char (point-min))
  (let ((address 0))
    (while (not (eobp))
      (let* ((i (min (- (point-max) (point)) 16))
	     (line (append (buffer-substring (point) (+ (point) i)) nil))
	     (hex nil)
	     (prt nil))
	(while line
	  (setq hex (cons (aref char-to-hex-vector (car line)) hex))
	  (setq prt (cons (aref char-to-prt-vector (car line)) prt))
	  (setq line (cdr line))
	  (if line
	      (progn
		(setq hex (cons (aref char-to-hex-vector (car line)) hex))
		(setq hex (cons " " hex))
		(setq prt (cons (aref char-to-prt-vector (car line)) prt))
		(setq line (cdr line)))))
	(delete-region (point) (+ (point) i))
	(insert (format "%08x: " address))
	(apply (function insert) (nreverse hex))
	(insert-char 32 (if (= i 16) 1
			  (+ (* (- 8 (/ i 2)) 5) 1 (* -2 (% i 2)))))
	(apply (function insert) (nreverse prt))
	(insert "\n")
	(setq address (+ address 16))))))
--
Rick Sladkey
jrs@world.std.com
Technical Details
Message-ID: <JRS.92Nov17212206@lepton.world.std.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!ferkel.ucsb.edu!taco!bu.edu!olivea!charnel!rat!usc!zaphod.mps.ohio-state.edu!uwm.edu!news.bbn.com!noc.near.net!mv!world!jrs
References: <m0mpyAL-0001BGC@fly.cnuce.cnr.IT>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!ferkel.ucsb.edu!taco!bu.edu!olivea!charnel!rat!usc!zaphod.mps.ohio-state.edu!uwm.edu!news.bbn.com!noc.near.net!mv!world!jrs
From: jrs@world.std.com (Rick Sladkey)
Newsgroups: gnu.emacs.help
Subject: Re: hexlify-buffer
Message-ID: <JRS.92Nov17212206@lepton.world.std.com>
Date: 18 Nov 92 02:22:05 GMT
References: <m0mpyAL-0001BGC@fly.cnuce.cnr.IT>
Sender: jrs@world.std.com (Rick Sladkey)
Organization: The Internet
Lines: 57
In-Reply-To: pot@fly.cnuce.cnr.it's message of 13 Nov 92 12:22:00 GMT