Entering a literal value

You can enter a literal value using the bases 10 (of course), 8 (octal), 16 (hexadecimal) or 2 (binary, only in c++14).

  • Decimal: any value not starting with a zero is interpreted as a normal (base 10) value.
  • Octal: any value starting with a zero and followed by any of the digits 0 through 7 is interpreted as a base 8 value.
  • Hexadecimal: any value starting with 0x or 0X (zero and lower or upper case X) and then followed by any valid hexadecimal ‘digit’ (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E and F) is interpreted as a base 16 value.

A suffix can be used on the literal to indicate the type of the literal:

  • No suffix: type is signed integer (int, long int or long long int)
  • U: type is unsigned integer (unsigned int, unsigned long int or unsigned long long int)
  • L: type is long integer (long int or long long int)
  • LU: type is unsigned long integer (unsigned long int or unsigned long long int)
  • LL: type is signed extra long integer (long long int, C++11)
  • LLU: type is unsigned extra long integer (unsigned long long int)

It is allowed to enter lower case suffixes also, but this is discouraged since the lower case l can easily be confused with 1 (one).


C++14 added the binary literal which is entered by starting a value with the characters 0b (zero and lower case b) or 0B (zero and upper case b):

and the possibility to add digit separators:

The digit separators are single-quote characters and does not change the way the literal value is interpreted. They are use only for make the value easier to read.


Leave a Reply

Your email address will not be published. Required fields are marked *