It is sometimes easier to use a number system based on 8 or 16 rather than 10 (our
standard decimal system). The number system based on 8 is called octal and uses the digits 0 through 7. In octal, the number 10 is the same as 8 in decimal. The base 16
number system is called hexadecimal and uses the digits 0 through 9 plus the letters
A through F, which stand for 10, 11, 12, 13, 14, and 15, respectively. For example, the
hexadecimal number 10 is 16 in decimal. Because these two number systems are
used frequently, C/C++ allows you to specify integer constants in hexadecimal or octal
instead of decimal. A hexadecimal constant must consist of a 0x followed by the
constant in hexadecimal form. An octal constant begins with a 0. Here are some
examples:
int hex = 0x80; /* 128 in decimal */
int oct = 012; /* 10 in decimal */
standard decimal system). The number system based on 8 is called octal and uses the digits 0 through 7. In octal, the number 10 is the same as 8 in decimal. The base 16
number system is called hexadecimal and uses the digits 0 through 9 plus the letters
A through F, which stand for 10, 11, 12, 13, 14, and 15, respectively. For example, the
hexadecimal number 10 is 16 in decimal. Because these two number systems are
used frequently, C/C++ allows you to specify integer constants in hexadecimal or octal
instead of decimal. A hexadecimal constant must consist of a 0x followed by the
constant in hexadecimal form. An octal constant begins with a 0. Here are some
examples:
int hex = 0x80; /* 128 in decimal */
int oct = 012; /* 10 in decimal */
No comments:
Post a Comment