How to display numbers in different bases under elisp?

As you know, elisp supports a number in different fundamentals, for example. #20r1j is 39 in the base-10. I want to show #20r1j as #20r1j . But (format "%d" #20r1j) gives me 39 . How to save the number in the source database?

+6
source share
1 answer

As a format string, you are practically limited in the bases that you can display:

% d means print as a decimal number (% o octal,% x hexa).
% X, like% x, but uses uppercase.

You can use calc library to manage this for you:

 (require 'calc-bin) (let ((calc-number-radix 20)) (math-format-radix 39)) "1J" (let ((calc-number-radix 20)) (math-format-radix #20r1j)) "1J" 

As with the read syntax used, valid calc-number-radix values ​​range from 2 to 36.

+8
source

Source: https://habr.com/ru/post/914394/


All Articles