问题
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