C++ Integer constant, octal hexadecimal

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
     

Step: 1 Create a project

Step: 2 Create a source file

Step: 3 Edit Source code

Step: 4 Runtime View

Step: 5b