什么是十进制的 0x10?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/692286/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 13:41:56  来源:igfitidea点击:

What is 0x10 in decimal?

c#numbershex

提问by Omar Abid

I have the following code:

我有以下代码:

SN.get_Chars(5)

SNis a string so this should give the 5th Char. Ok!

SN是一个字符串,所以这应该给出第 5 个字符。好的!

Now I have another code but: SN.get_Chars(0x10)

现在我有另一个代码,但是: SN.get_Chars(0x10)

I wonder what 0x10 is? Is it a number? If it's so, then what is it in decimal notation?

我想知道 0x10 是什么?它是一个数字吗?如果是这样,那么十进制表示法是什么?

采纳答案by Michael

0x means the number is hexadecimal, or base 16.

0x 表示数字是十六进制的,或以 16为基数。

0x10 is 16.

0x10 是 16。

回答by sipwiz

It's a hex number and is 16 decimal.

它是一个十六进制数,十进制为 16。

回答by paxdiablo

0xNNNN(not necessarily four digits) represents, in C at least, a hexadecimal (base-16 because 'hex' is 6 and 'dec' is 10 in Latin-derived languages) number, where Nis one of the digits 0through 9or Athrough F(or their lower case equivalents, either representing 10 through 15), and there may be 1 or more of those digits in the number. The other way of representing it is NNNN16.

0xNNNN(不一定是四位数)表示,至少在 C 中,十六进制(基数为 16,因为 'hex' 是 6,'dec' 是 10 在拉丁派生语言中)数字,其中N是一个数字0通过9A通过F(或它们的小写等价物,代表 10 到 15),并且数字中可能有 1 个或多个这些数字。另一种表示它的方式是 NNNN 16

It's very useful in the computer world as a single hex digit represents four bits (binary digits). That's because four bits, each with two possible values, gives you a total of 2 x 2 x 2 x 2or 16(24) values. In other words:

它在计算机世界中非常有用,因为单个十六进制数字代表四位(二进制数字)。那是因为四位,每个位有两个可能的值,给你总共2 x 2 x 2 x 216(2 4) 个值。换句话说:

  _____________________________________bits____________________________________
 /                                                                             \
+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
| bF | bE | bD | bC | bB | bA | b9 | b8 | b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 |
+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
 \_________________/ \_________________/ \_________________/ \_________________/ 
      Hex digit           Hex digit           Hex digit           Hex digit

A base-X number is a number where each position represents a multiple of a power of X.

基数 X 数是一个数,其中每个位置代表 X 的幂的倍数。



In base 10, which we humans are used to, the digits used are 0through 9, and the number 730410is:

在我们人类习惯的基数 10 中,使用的数字是0通过9,数字 7304 10是:

  • (7 x 103) = 700010; plus
  • (3 x 102) = 30010; plus
  • (0 x 101) = 010; plus
  • (4 x 100) = 410; equals 7304.
  • (7 x 10 3) = 7000 10; 加
  • (3 x 10 2) = 300 10; 加
  • (0 x 10 1) = 0 10; 加
  • (4 x 10 0) = 4 10; 等于 7304。


In octal, where the digits are 0through 7. the number 7548is:

在八进制中,数字0通过7. 数字 754 8是:

  • (7 x 82) = 44810; plus
  • (5 x 81) = 4010; plus
  • (4 x 80) = 410; equals 49210.
  • (7 x 8 2) = 448 10; 加
  • (5 x 8 1) = 40 10; 加
  • (4 x 8 0) = 4 10; 等于 492 10

Octal numbers in C are preceded by the character 0so 0123is not 123 but is instead (1 * 64) + (2 * 8) + 3, or 83.

C 中的八进制数以字符开头,0因此0123不是 123,而是 (1 * 64) + (2 * 8) + 3,或 83。



In binary, where the digits are 0and 1. the number 10112is:

在二进制中,数字是01。数字 1011 2是:

  • (1 x 23) = 810; plus
  • (0 x 22) = 010; plus
  • (1 x 21) = 210; plus
  • (1 x 20) = 110; equals 1110.
  • (1 x 2 3) = 8 10; 加
  • (0 x 2 2) = 0 10; 加
  • (1 x 2 1) = 2 10; 加
  • (1 x 2 0) = 1 10; 等于 11 10


In hexadecimal, where the digits are 0through 9and Athrough F(which represent the "digits" 10through 15). the number 7F2416is:

在十六进制中,数字是0通过9A通过F(代表“数字”10通过15)。数字 7F24 16是:

  • (7 x 163) = 2867210; plus
  • (F x 162) = 384010; plus
  • (2 x 161) = 3210; plus
  • (4 x 160) = 410; equals 3254810.
  • (7 x 16 3) = 28672 10; 加
  • (F x 16 2) = 3840 10; 加
  • (2 x 16 1) = 32 10; 加
  • (4 x 16 0) = 4 10; 等于 32548 10

Your relatively simple number 0x10, which is the way C represents 1016, is simply:

您相对简单的 number 0x10,即 C 代表 10 16的方式,很简单:

  • (1 x 161) = 1610; plus
  • (0 x 160) = 010; equals 1610.
  • (1 x 16 1) = 16 10; 加
  • (0 x 16 0) = 0 10; 等于 16 10

As an aside, the different bases of numbers are used for many things.

顺便说一句,不同的数字基数用于许多事情。

  • base 10 is used, as previously mentioned, by we humans with 10 digits on our hands.
  • base 2 is used by computers due to the relative ease of representing the two binary states with electrical circuits.
  • base 8 is used almost exclusively in UNIX file permissions so that each octal digit represents a 3-tuple of binary permissions (read/write/execute). It's also used in C-based languages and UNIX utilities to inject binary characters into an otherwise printable-character-only data stream.
  • base 16 is a convenient way to represent four bits to a digit, especially as most architectures nowadays have a word size which is a multiple of four bits.
  • base 64 is used in encoding mail so that binary files may be sent using only printable characters. Each digit represents six binary digits so you can pack three eight-bit characters into four six-bit digits (25% increased file size but guaranteed to get through the mail gateways untouched).
  • as a semi-useful snippet, base 60 comes from some very old civilisation (Babylon, Sumeria, Mesopotamia or something like that) and is the source of 60 seconds/minutes in the minute/hour, 360 degrees in a circle, 60 minutes (of arc) in a degree and so on [not really related to the computer industry, but interesting nonetheless].
  • as an even less-useful snippet, the ultimate question and answer in The Hitchhikers Guide To The Galaxywas "What do you get when you multiply 6 by 9?" and "42". Whilst same say this is because the Earth computer was faulty, others see it as proof that the creator has 13 fingers :-)
  • 如前所述,我们手上有 10 个数字的人使用基数 10。
  • 由于用电路表示两个二进制状态相对容易,因此计算机使用基数 2。
  • base 8 几乎专门用于 UNIX 文件权限,因此每个八进制数字代表二进制权限的 3 元组(读/写/执行)。它还在基于 C 的语言和 UNIX 实用程序中用于将二进制字符注入到其他可打印的仅字符数据流中。
  • 基数 16 是一种将四位表示为一个数字的便捷方式,尤其是现在大多数架构的字长是四位的倍数。
  • base 64 用于对邮件进行编码,以便可以仅使用可打印字符发送二进制文件。每个数字代表六个二进制数字,因此您可以将三个八位字符打包成四个六位数字(文件大小增加 25%,但保证通过邮件网关不受影响)。
  • 作为一个半有用的片段,base 60 来自一些非常古老的文明(巴比伦、苏美尔、美索不达米亚或类似的东西)并且是一分钟/小时中 60 秒/分钟、360 度一圈、60 分钟( of arc) 学位等等[与计算机行业没有真正的关系,但仍然很有趣]。
  • 作为一个更没用的片段,《银河系漫游指南》中的最终问题和答案是“当你将 6 乘以 9 时,你会得到什么?” 和“42”。虽然同样说这是因为地球计算机有问题,但其他人认为这是创造者有 13 个手指的证据:-)

回答by jab

Notice that '10' is the representation of the base in that base:

请注意,“10”是该基数中基数的表示:

10 is 2(decimal) in base-2

10 是以 2 为底的 2(十进制)

10 is 3(decimal) in base-3

10 是以 3 为底的 3(十进制)

...

...

10 is 10(decimal) in base-10

10 是以 10 为底的 10(十进制)

...

...

10 is 16(decimal) in base-16 (hexadecimal)

10 是 base-16(十六进制)中的 16(十进制)

...

...

10 is 1024(decimal) in base-1024

10 是以 1024 为基数的 1024(十进制)

...and so on

...等等

回答by mdo123

The simple version is 0x is a prefix denoting a hexadecimal number, source.

简单的版本是 0x 是一个前缀,表示一个十六进制数,source

So the value you're computing is afterthe prefix, in this case 10.

所以,你的计算值的前缀,在这种情况下,10。

But that is not the number 10. The most significant bit 1denotes the hex value while 0denotes the units.

但这不是数字 10。最高位1表示十六进制值,而0表示单位。

So the simple math you would do is

所以你要做的简单数学是

0x10

0x10

1 * 16 + 0 = 16

Note - you use 16 because hex is base 16.

注意 - 您使用 16 是因为十六进制是以 16 为底的。

Another example:

另一个例子:

0xF7

0xF7

15 * 16 + 7 = 247

You can get a list of values by searching for a hex table. For instance in this chartnotice F corresponds with 15.

您可以通过搜索十六进制表来获取值列表。例如在此图表中,通知 F 对应于 15。