[英]In Squeak Smalltalk, what can I do to display a number in any base I want?
I have done a basic arithmetic calculation and got the answer aa 我已经完成了基本的算术运算并得到了答案aa
Here is the Smalltalk code in Squeak: 这是Squeak中的Smalltalk代码:
Transcript show: 'aa='.
Transcript show: 23124234 * 431213; cr.
The output is aa=9971470315842 输出为aa = 9971470315842
9971470315842 is a decimal number. 9971470315842是十进制数字。
What can I do to make a 10-based number displayed based on any integer I want ?? 我该怎么做才能使基于10的数字显示在我想要的任何整数的基础上?
Say, 55-based, 33-based, 2999-base. 假设基于55,基于33,基于2999。 Any positive integer. 任何正整数。
In Squeak, you can use 在Squeak中,您可以使用
12345 printStringBase: 17.
'28C3'
You can also prepend the radix (base) and re-interpret the number 您还可以在基数前面加上基数并重新解释数字
17r28C3.
12345
The behavior is well defined up to base 36 (10 digits and 26 latin letters). 行为已明确定义,以36为基数(10位数字和26个拉丁字母)。 Then you might get some output with more character codes, but you will not be able to re-interpret the numbers. 然后,您可能会得到带有更多字符代码的输出,但是您将无法重新解释数字。
This also work with floating point numbers: 这也适用于浮点数:
Float pi printStringBase: 5.
'3.0323221430334324112412'
5r3.0323221430334324112412.
3.141592653589793
Unfortunately, we can't reinterpret them above base 14 because there is an ambiguity with exponent letter e (once upon a time, only uppercase letters were used as digits, and there were no ambiguity). 不幸的是,我们无法在基数14之上重新解释它们,因为存在带指数字母e的歧义(从前,只有大写字母用作数字,并且没有歧义)。
Note that you can find methods with the MethodFinder tool. 请注意,您可以使用MethodFinder工具查找方法。
Open a method finder and enter the receiver, arguments and expected results, for example with: 打开方法查找器,然后输入接收器,参数和预期结果,例如:
34. 17. '20'
the method finder will display 2 matching methods, 34 printStringBase: 17 --> '20'
and 34 radix: 17 --> '20'
方法查找器将显示2个匹配方法,即34 printStringBase: 17 --> '20'
和34 radix: 17 --> '20'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.