From: pjb@informatimago.com (Pascal J. Bourguignon)
To: help-gnu-emacs@gnu.org
Subject: Re: How do I convert hex numbers to decimal ?
Date: Mon, 07 Sep 2009 09:12:54 +0200 [thread overview]
Message-ID: <87ljkrns7d.fsf@galatea.local> (raw)
In-Reply-To: 1bfadfca-66ba-4aec-bb90-eb3a460c660c@l13g2000yqb.googlegroups.com
bolega <gnuist006@gmail.com> writes:
> I have a bunch of related questions, but the solution is desired in
> emacs lisp and to work inside emacs only.
Then do not post in the irrelevant newsgroups!
> 1) How do I convert hex numbers to decimal ?
Wrong question.
Numbers are not hex or decimal. Numbers are.
Now, you can represent a number with a base system, such as base
sixteen or base ten. And of course, you can convert back a
representation in a give base into a number.
http://en.wikipedia.org/wiki/Positional_notation
http://groups.google.com/group/comp.programming/browse_thread/thread/5da7ce38ff66d160/f6088718a82956dd?q=convert+base+author:Pascal+author:Bourguignon#f6088718a82956dd
(You can use the function convert-to-base and convert-from-base from
that post, just (require 'cl) and remove the colon before the keywords
of the loops).
> 2) How do I convert ascii to the character that it represents, short
> of a table ? Any function or simpler algorithm ?
Wrong question.
ASCII *is* the convertion table. You cannot convert a table into a
single character.
ASCII defines the one-to-one mapping between codes (numbers) between 0
and 127, and the union of a set of control functions and a set of
characters.
In emacs, characters are represented by their code value, which, in
the case of the characters in the ASCII character set, is their ASCII
code. So, in emacs, like in C, you do not need any function to
convert between them.
Or, you can write:
(defun char-code (char) char)
(defun code-char (code) code)
(format "code = %d" (char-code ?a)) --> "code = 97"
(format "char = %c" (code-char 97)) --> "char = a"
> 3) What are the variables and how to set their values ?
>
> read-quoted-char-radix
> quoted-char-radix
You can fetch the documentation of a variable by typing C-h v.
Move the cursor on one variable, and type C-h v RET
or type C-h v and the name of the variable RET
If the variable is customizable, you can change its value with
(customize-variable 'variable)
otherwise you can always set it:
(require 'cl)
(setf variable value)
> 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 ?
You can find the command bound to a keychord with C-h k followed by the keychord.
So, in this case: C-h k C-x =
--
__Pascal Bourguignon__
next prev parent reply other threads:[~2009-09-07 7:12 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-07 1:03 How do I convert hex numbers to decimal ? bolega
2009-09-07 1:11 ` Janis Papanagnou
2009-09-07 14:44 ` Wang Lei
2009-09-07 2:56 ` Eli Zaretskii
[not found] ` <mailman.6147.1252292305.2239.help-gnu-emacs@gnu.org>
2009-09-07 5:52 ` bolega
2009-09-07 6:38 ` Teemu Likonen
2009-09-07 7:12 ` Pascal J. Bourguignon [this message]
2009-10-05 7:05 ` josephoswald+gg@gmail.com
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ljkrns7d.fsf@galatea.local \
--to=pjb@informatimago.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.