在 Perl 6 中与八进制相互转换
Converting to and from octal in Perl 6
如果我们有一个八进制数,例如0o157
, Perl 6 可以将其转换成十进制:
> 0o157
111
我们不允许删除此 o
的八进制表示形式:
> 0157
Potential difficulties:
Leading 0 has no meaning. If you meant to create an octal number, use '0o' prefix; like, '0o157'. If you meant to create a string, please add quotation marks.
------> 0157⏏<EOL>
现在让我们进行反向转换,从十进制to octal:
> printf "%#o\n", 111
0157
问题是:为什么现在八进制的0
后面没有o
了?
同时,如果我们转换为十六进制,x
将在那里:
> printf "%#x\n", 111
0x6f
The question is: why is there now no o
after 0
in the octal representation?
(s)printf 是一个非常普遍使用的函数,并直接移植到 Perl 6。它意味着与其他语言的 printf
函数兼容,而不是与 Perl 6 输入语法兼容。
Perl 5 的 printf
行为相同,因此它的行为可能是直接复制的。
如果我们有一个八进制数,例如0o157
, Perl 6 可以将其转换成十进制:
> 0o157
111
我们不允许删除此 o
的八进制表示形式:
> 0157
Potential difficulties:
Leading 0 has no meaning. If you meant to create an octal number, use '0o' prefix; like, '0o157'. If you meant to create a string, please add quotation marks.
------> 0157⏏<EOL>
现在让我们进行反向转换,从十进制to octal:
> printf "%#o\n", 111
0157
问题是:为什么现在八进制的0
后面没有o
了?
同时,如果我们转换为十六进制,x
将在那里:
> printf "%#x\n", 111
0x6f
The question is: why is there now no
o
after0
in the octal representation?
(s)printf 是一个非常普遍使用的函数,并直接移植到 Perl 6。它意味着与其他语言的 printf
函数兼容,而不是与 Perl 6 输入语法兼容。
Perl 5 的 printf
行为相同,因此它的行为可能是直接复制的。