From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: pjb@informatimago.com (Pascal J. Bourguignon) Newsgroups: gmane.emacs.help Subject: Re: How do I convert hex numbers to decimal ? Date: Mon, 07 Sep 2009 09:12:54 +0200 Organization: Informatimago Message-ID: <87ljkrns7d.fsf@galatea.local> References: <1bfadfca-66ba-4aec-bb90-eb3a460c660c@l13g2000yqb.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1252309253 23124 80.91.229.12 (7 Sep 2009 07:40:53 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 7 Sep 2009 07:40:53 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Sep 07 09:40:46 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MkYqB-000874-2a for geh-help-gnu-emacs@m.gmane.org; Mon, 07 Sep 2009 09:40:43 +0200 Original-Received: from localhost ([127.0.0.1]:54872 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MkYqA-0001Z0-EA for geh-help-gnu-emacs@m.gmane.org; Mon, 07 Sep 2009 03:40:42 -0400 Original-Path: news.stanford.edu!usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 86 Original-X-Trace: individual.net +6WXs7cK//257FJD3BlJnAwrvqGUi0kBOuymcZrXrkNsu2MlNI Cancel-Lock: sha1:ZDliMDI2ZTIzMjRiMGJkZGQxNDdmNTQ1MWRmY2UxMTE5NjlmNTcyNw== sha1:NEuoIEgb70UmRsvFK6NV/GptVt4= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.3 (darwin) Original-Xref: news.stanford.edu gnu.emacs.help:172788 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:67925 Archived-At: bolega 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__