在使用 REPL 的 SWI-Prolog 中,可以轻松地从任何基数转换为基数 10,例如
?- X = 16'FF.
X = 255.
?- X = 2'11111111.
X = 255.
然而这失败了。 (没想到它会起作用,但显示了我的想法。)
?- 2'X = 16'FF.
ERROR: Syntax error: Operator expected
ERROR:
ERROR: ** here **
ERROR: 2'X = 16'FF .
在SWI-Prolog中,您可以使用r
for radix in format/2 http://eu.swi-prolog.org/pldoc/doc_for?object=format/2:
Print integer in radix numeric argument notation. Thus ~16r prints its argument hexadecimal. The argument should be in the range [2, ... , 36]. Lowercase letters are used for digits above 9. The colon modifier may be used to form locale-specific digit groups.
Example:
?- format("~2r", 0xFF).
11111111
true.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)