简体   繁体   English

在Squeak Smalltalk中,我该怎么办才能显示我想要的任何基数的号码?

[英]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.

相关问题 如何将像 e+308(以 10 为底)这样的十进制指数转换为具有等效大小的十六进制数? - How do I convert a decimal exponent like e+308 (in base 10) to a hexadecimal number with equivalent magnitude? 我尝试读取二进制文件并希望以转储之类的格式显示它 - I try to read a binary file and want to display it in a format like a dump 如何生成具有不同基数的十六进制字符序列? - How do I generate character sequences like hexadecimal with a different base? 我可以将十进制整数转换为十六进制数字吗? - Can I convert a decimal int to HEX number? 如何将输入存储为十六进制数字? - How can I store input as a hexadecimal number? SQL 将数字转换为任何基数的字符串表示形式(二进制、十六进制、...、十六进制) - SQL convert number to string representation of any base (binary, hexadecimal, ..., tricontahexadecimal) 替代位置基础系统(十六进制、八进制、二进制)如何工作? 如何将它们转换为十进制? - How do alternative positional base systems (hexadecimal, octal, binary) work? How do I convert them to decimal? 如何让Netbeans默认为Hex显示以获取监视变量? - How do I get Netbeans to default to Hex display for watch variables? 如何找出这段代码中的颜色? - How can I figure out what colors I have in this code? 如何从32位数中提取位 - How do I extract bits from 32 bit number
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM