如何在elisp中显示不同的基数? [英] How to display numbers in different bases under elisp?
本文介绍了如何在elisp中显示不同的基数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#20r1j
等于39在base-10。我想显示#20r1j
为#20r1j
。但是(格式%d#20r1j)
给我 39
。 解决方案
作为格式字符串,您可以在显示的基础上相当有限:
%d表示打印为十进制数(%o八进制,%x十六进制)。
%X但是使用大写字母。
然而,您可以使用calc库来管理这个:
(require'calc-bin)
(let((calc-number -radix 20))
(math-format-radix 39))
1J
(let((calc-number-radix 20))
math-format-radix#20r1j))
1J
与读取语法一样您正在使用,允许的值为$ code> calc-number-radix 从2到36。
As we know, elisp supports number in different bases, e.g. #20r1j
equals to 39 in base-10. I want to display #20r1j
as #20r1j
. But (format "%d" #20r1j)
gives me 39
. How to keep the number in its original base?
解决方案
As a format string, you are quite limited in the bases you can display:
%d means print as number in decimal (%o octal, %x hex).
%X is like %x, but uses upper case.
You can use the calc library to manage this for you, however:
(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 you're using, allowed values of calc-number-radix
run from 2 to 36.
这篇关于如何在elisp中显示不同的基数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文