打字时如何表示不同的数字系统?

发布于 2024-09-24 16:57:11 字数 239 浏览 11 评论 0原文

我知道这不完全是一个编程问题,但它与我的主题相关。如何在文本中表示不同的数字系统? (我所说的文本是指能够以适当的速度键入,而不是从另一个程序复制粘贴它。)例如,如果我有一个以 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

肤浅与狂妄 2024-10-01 16:57:12

许多编程语言中的惯例是

0b1001

“b”表示二进制。其他约定包括十六进制以 0x 开头,八进制以 0(后跟其他数字)开头。

A convention in many programming languages is

0b1001

where the "b" indicates binary. Other conventions include starting with 0x for hexadecimal and starting with just 0 (followed by other digits) for octal.

做个少女永远怀春 2024-10-01 16:57:12

对于十六进制,您可以在其前面添加 0x 前缀。

0xFF

对于二进制,0b

0b101

对于八进制,0o

0o44

另外,更明确吗?

dec(123)
hex(0AF)
bin(101)
oct(111)

For hex, you'd prefix it with 0x.

0xFF

For Binary, a 0b

0b101

For Octal, a 0o

0o44

Alternatively, be more explicit?

dec(123)
hex(0AF)
bin(101)
oct(111)
难以启齿的温柔 2024-10-01 16:57:12

我看到的约定是,就像脱字符号表示上标(对于求幂)一样,下划线表示下标。因此,将示例转换为 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.

薄荷→糖丶微凉 2024-10-01 16:57:12

我认为这很大程度上取决于您最终想要如何/为什么/如何处理数据。

对我来说,使用 ^ 是合乎逻辑的,因为它输入起来很快,但不熟悉该符号的人可能会错误地解释它。

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.

浪菊怪哟 2024-10-01 16:57:12

基数的表示法根据编程语言的不同而有所不同(正如我在

  • 十进制表示法往往是默认的(没有特定的表示法)。
  • 十六进制往往以 #0x 为前缀,或使用 h 后缀:0xA0#A0A0h
  • 某些语言使用 0 前缀来表示八进制表示法(例如 0777)。
  • 二进制表示法不太常见(通常使用十六进制,因为它使表示法更加紧凑,并且最终使用八位字节的正确填充)。不过,您可以使用 0b10101010b。同样,这取决于语言以及编译器是否支持它。

以上所有内容都取决于编程语言。如果只是为了以文本形式书写,那么这两种约定都可以。当然,如果你正在写一本书,请不要改变你在中间使用的约定......

The notations for the base vary depending on the programming language (as I was saying in a comment to this question).

  • Decimal notation tends to be the default (no specific notation).
  • Hexadecimal tends to be prefixed with # or 0x or use the h suffix: 0xA0, #A0 or A0h.
  • Some languages use a 0 prefix to represent octal notation (e.g. 0777).
  • Binary notation is less common (often hexadecimal is used instead, as it makes the notation a bit more compact and ends up using the right padding for octets). You could however use 0b1010 or 1010b. 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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文