Objectives :
- Integer constant: e.g. int n1 = 20;
- Forcing integer constant as long data type int n1 = 2010L
for signed and
int n1 = 2015ul for unsigned
- Literals for Integers: by default, C++ considers that all
integer constants are decimal types (base 10).
- Literal integers can be expressed in decimal, octal, and
hexadecimal notations.
- >Octal
: if a an integer begins with zero (022), an integer is treated
as to be an octal (Example below taken from Unleashed C++
page-11.
- >> Octal numbers use the base 8, and can therefore only use
the digits 0-7.
0134 = 1 × 82 + 3 × 81 + 4 × 80
= 64 + 24 + 4 = 92
- >Hexadecimal: if an integer begins with 0x, the same is considered to
be hexadecimal :Hexadecimal numbers use the base 16, and
therefore use the letter A-F (or a-f) to represent,
respectively, 10-15.
0x5C = 5 × 161
+ 12 × 160
= 80 + 12 = 92
- myHexaOctaDeca1
- code :
myIntHexOctBase1.txt
|