C: 0x11 in Decimal

蓝咒 提交于 2019-12-10 12:14:19

问题


Sorry about this basic question, but why 0x11 is 17 in decimal (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.


回答1:


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.




回答2:


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




回答3:


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




回答4:


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

Just like:

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



回答5:


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

Counting from 0 in both base 16 and base 10:

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:

1116 = 1 * 16 + 1 = 1710




回答6:


Well, maybe because 0x11 IS 17 in decimal?




回答7:


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

add them together 16 + 1 = 17



来源:https://stackoverflow.com/questions/6405033/c-0x11-in-decimal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!