打字时如何表示不同的数字系统?
我知道这不完全是一个编程问题,但它与我的主题相关。如何在文本中表示不同的数字系统? (我所说的文本是指能够以适当的速度键入,而不是从另一个程序复制粘贴它。)例如,如果我有一个以 2 为基数的数字,我该如何键入它,以便其他人可以理解它是一个以 2 为基数的数字。在纸面上你可以做类似 (1001)2 的事情,其中 2 是一个小索引。您是否必须在 2 之前输入一些特定符号,以便其他人将其理解为下标? (求幂使用符号 ^ 来表示。)或者这只是随机的并且不存在标准?
I know that this isn't exactly a programming question, but it's related to the subject for me. How do you denote different numeral systems in just text? (By text I mean able to type at a proper speed and not copy-pasting it from another program.) For example if i have a number in base 2 how do I type it so others can understand that it's a base 2 number. On paper you can do something like (1001)2 where 2 is a small index. Is there some specific symbol that you have to type before the 2 so that others understand it as subscript? (Exponentiation uses the symbol ^ for this.) Or is it all just random and no standard exists in it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
许多编程语言中的惯例是
“b”表示二进制。其他约定包括十六进制以 0x 开头,八进制以 0(后跟其他数字)开头。
A convention in many programming languages is
where the "b" indicates binary. Other conventions include starting with 0x for hexadecimal and starting with just 0 (followed by other digits) for octal.
对于十六进制,您可以在其前面添加
0x
前缀。对于二进制,
0b
对于八进制,
0o
另外,更明确吗?
For hex, you'd prefix it with
0x
.For Binary, a
0b
For Octal, a
0o
Alternatively, be more explicit?
我看到的约定是,就像脱字符号表示上标(对于求幂)一样,下划线表示下标。因此,将示例转换为 ASCII 的最“字面”方式是 1001_2。不过,我同意 JacobM 的观点; 0b 前缀是明确的,不太可能被误解。
The convention I've seen is that, just as a caret indicates superscript (as for exponentiation), an underscore indicates subscript. So the most "literal" way to translate your example to ASCII would be 1001_2. I agree with JacobM, though; the 0b prefix is unambiguous and unlikely to be misunderstood.
我认为这很大程度上取决于您最终想要如何/为什么/如何处理数据。
对我来说,使用 ^ 是合乎逻辑的,因为它输入起来很快,但不熟悉该符号的人可能会错误地解释它。
I think a lot of this is going to depend on how/why/what you want to do with the data in the end.
For me, the ^ is logical to use, as it is quick to type, BUT it could be interpreted incorrectly by someone unfamiliar with the notation.
基数的表示法根据编程语言的不同而有所不同(正如我在
#
或0x
为前缀,或使用h
后缀:0xA0
、#A0
或A0h
。0
前缀来表示八进制表示法(例如0777
)。0b1010
或1010b
。同样,这取决于语言以及编译器是否支持它。以上所有内容都取决于编程语言。如果只是为了以文本形式书写,那么这两种约定都可以。当然,如果你正在写一本书,请不要改变你在中间使用的约定......
The notations for the base vary depending on the programming language (as I was saying in a comment to this question).
#
or0x
or use theh
suffix:0xA0
,#A0
orA0h
.0
prefix to represent octal notation (e.g.0777
).0b1010
or1010b
. Again, this depends on the language and whether the compiler supports it.All of the above depend on the programming language. If it's just for writing in text, either of these conventions should do. Of course, if you're writing a book don't change the convention you're using in the middle...