C语言 C: 0x11 十进制

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6405033/
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-09-02 08:57:36  来源:igfitidea点击:

C: 0x11 in Decimal

cdecimalhex

提问by Yonatan

Sorry about this basic question, but why 0x11is 17in decimal (print(%d, 0x11)=17?

抱歉这个基本问题,但为什么0x1117十进制(print(%d, 0x11)=17

I search information about the way to convert from hex to dec, but it doesn't talk about this sort of numbers.

我搜索有关从十六进制转换为十进制的方法的信息,但它没有谈论这种数字。

回答by codekaizen

Just like "11" in base ten means "1 ten" and "1 one", "11" in base 16 (i.e. hex) means "1 sixteen" and "1 one" - or 17 in base 10.

就像基数 10 中的“11”表示“1 十”和“1 一”一样,基数 16(即十六进制)中的“11”表示“16”和“1 一” - 或基数 17 中的 17。

回答by patapizza

0x11 = 1*16^1 + 1*16^0 = 17. (Like 17 = 1 * 10^1 + 7 * 10^0.)

0x11 = 1*16^1 + 1*16^0 = 17。(比如 17 = 1 * 10^1 + 7 * 10^0。)

回答by geofftnz

0xat the start of a number means that the compiler will read it as hexadecimal. 0x11= 1 * 16 + 1 = 17

0x在数字的开头意味着编译器会将其读取为十六进制。0x11=1 * 16 + 1 = 17

回答by maerics

0x11 =   1 * 16^1 (16)
       + 1 * 16^0 ( 1)
     -----------------
      0x11        (17)

Just like:

就像:

  17 =   1 * 10^1 (10)
       + 7 * 10^0 ( 7)
     -----------------
        17        (17)

回答by kevinji

Hexadecimal counts with 16 digits, instead of 10. To account for the extra 6 digits, it uses letters Ato F.

十六进制计数为 16 位,而不是 10。为了说明额外的 6 位,它使用字母AF

Counting from 0 in both base 16 and base 10:

以 16 和 10 为基数从 0 开始计数:

0, 1, 2, 3, 4, 5, 6, 7, 8, 9,  A,  B,  C,  D,  E,  F, 10, 11 (base 16)
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 (base 10)

Also, to convert from base 16 to base 10:

此外,要从基数 16 转换为基数 10:

1116= 1 * 16 + 1 = 1710

11 16= 1 * 16 + 1 = 17 10

回答by Vinicius Kamakura

Well, maybe because 0x11 IS17 in decimal?

好吧,也许是因为 0x11十进制的 17?

回答by Paul Sullivan

here is an easy way of seeing

这是一个简单的观看方式

128 64 32 16 8 4 2 1 = Decimal values of the...
    0   0   0   1 0 0 0 1 = Boolean switches that are ON or OFF

128 64 32 16 8 4 2 1 = 十进制值...
    0 0 0 1 0 0 0 1 = 打开或关闭的布尔开关

add them together 16 + 1 = 17

将它们加在一起 ​​16 + 1 = 17