What is the difference between "18" and "0x18"?

Possible duplicate:
What is 0x10 in decimal format?

I noticed that

Console.WriteLine(18);

writes 18 but

Console.WriteLine(0x18);

writes 24. What does this mean?

+3
source share
1 answer

The prefix 0xindicates that the next number is in hexadecimal format . those. the base number system 16. Thus, the number 0x18(in the base of 10) (1 * 16 ^ 1) + (8 * 16 ^ 0) = 24 (remember: 16 ^ 0 = 1).

Your example without a prefix is 18already in base 10, as you probably expect.

+17
source

Source: https://habr.com/ru/post/1765457/


All Articles