[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How do I convert hex numbers to decimal ?
From: |
Alan Mackenzie |
Subject: |
Re: How do I convert hex numbers to decimal ? |
Date: |
Sun, 4 Oct 2009 14:00:12 +0000 (UTC) |
User-agent: |
tin/1.6.2-20030910 ("Pabbay") (UNIX) (FreeBSD/4.11-RELEASE (i386)) |
[Followup-To: set]
In comp.lang.lisp bolega <gnuist006@gmail.com> wrote:
> I have a bunch of related questions, but the solution is desired in
> emacs lisp and to work inside emacs only.
> 1) How do I convert hex numbers to decimal ?
You're talking here about a string like "4000FFFF"? You want to "read"
(as in read-eval-print loop) the string, either by setting the number
base first or prefixing the string with "#x". Having done that, you can
print (as in read-eval-print loop) it in decimal. Something like this:
(setq myval (read (concat "#x" instring)))
(prin1-to-string myval)
(untested) will return the decimal string equivalent.
> 2) How do I convert ascii to the character that it represents, short
> of a table ? Any function or simpler algorithm ?
In GNU Emacs (but not XEmacs), a character is simply an integer. So do
the first part of the above to turn "41" into 65, which is "A".
> 3) What are the variables and how to set their values ?
> read-quoted-char-radix
> quoted-char-radix
In Emacs, do C-h v, then type in the variable name. To set an Emacs
variable, do M-x set-variable<CR>, then follow the prompts.
> 4) How do i find the emacs lisp code for C-x = to see how it gives the
> ascii of the char at the cursor and then use to find the reverse, ie
> ascii to char ?
General method: C-h k <key sequence>, in this case, C-h k C-x =. This
brings up a *Help* window, identifying the the source file, in this case
simple.el. Click on or move to and type <CR> on "simple.el". This
opens simple.el at the right place.
> Thanks a lot to the star who can explain.
No problem! All the best!
--
Alan Mackenzie (Nuremberg, Germany).
- Re: How do I convert hex numbers to decimal ?,
Alan Mackenzie <=