Elisp: Convert Hexadecimal to Decimal

By Xah Lee. Date: . Last updated: .

Here's how to convert hexadecimal/decimal in lisp code.

Decimal to Hexadecimal

use format

;; decimal to hexadecimal
(string-equal
 (format "%x" 1000)
 "3e8"
 )
;; true

Hexadecimal to Decimal

use string-to-number

;; hexadecimal to decimal

(let (xinput)
  (setq xinput "3e8")
  (equal
   (string-to-number xinput 16)
   1000
   ))
;; true

Convert Hexadecimal/Decimal