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

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

Re: Inspecting integer, float values from hexl-mode


From: despen
Subject: Re: Inspecting integer, float values from hexl-mode
Date: Fri, 04 Feb 2011 10:38:21 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

Alberto Luaces <aluaces@udc.es> writes:

> Hello,
>
> I'm inspecting a binary file with hexl-mode. I need to select some bytes
> and then be able to interpret their value as integer, or as float. I was
> wondering if there is a method for doing this since it seems that
> hexl-mode doesn't do that by default.

hexl-mode shows integers in byte order.
On Intel platforms that makes mental conversion from hex to integer
just a little harder.

I use this to convert hex in logical byte order to decimal:

(defun x2c (num &optional arg)
  "convert hex arg or word at point to decimal."
  (interactive
   (list
    (let* ((num-chars "0-9A-Fa-f")
           (ins-at (point))
           (default-hex (save-excursion
                      (buffer-substring
                       (progn
                         (re-search-backward "\\sw" nil t) ;backup a word
                         (skip-chars-backward num-chars) (point)) ;back up hex 
chr
                       (progn (skip-chars-forward num-chars) (point)))))
           (override-hex (read-string
                   (if (equal default-hex "") "Hex Number: "
                     (concat "Hex Number: (default " default-hex ") ")))))
      (if (equal override-hex "") default-hex override-hex))
    (prefix-numeric-value current-prefix-arg)))
  (insert (format " = %s" (int-to-string (string-to-int num 16)))))


reply via email to

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