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

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

Re: How do I convert hex numbers to decimal ?


From: Teemu Likonen
Subject: Re: How do I convert hex numbers to decimal ?
Date: Mon, 07 Sep 2009 09:38:32 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

On 2009-09-06 22:52 (-0700), bolega wrote:

> What I want is a function like this:
>
> (function "%1F)

Where that "%" comes from? Do you want your function to require it?
Here's an example:

    (defun my-hex-to-int (hexstring)
      (car (read-from-string (replace-regexp-in-string
                              "\\`%" "#x" hexstring))))

    (my-hex-to-int "%1F")
    => 31

Or without the % prefix:

    (defun my-hex-to-int2 (hexstring)
      (car (read-from-string (concat "#x" hexstring))))

    (my-hex-to-int2 "1F")
    => 31

> what I want is a function like this:
>
> (function "%3F")              and it converts it and returns or
> prints ? either an existing facility or combination thereof.

Do you mean like this?

    (format "%c" (my-hex-to-int "%3F"))
    => "?"

It returns a string containing that character.


reply via email to

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