2.4.2 Based Literals


Based Literals

1 [ {literal (based)} {binary literal} {base 2 literal} {binary (literal)} {octal literal} {base 8 literal} {octal (literal)} {hexadecimal literal} {base 16 literal} {hexadecimal (literal)} A based_literal is a numeric_literal expressed in a form that specifies the base explicitly.] 


2 based_literal ::= base # based_numeral [.based_numeral] # [exponent]
3 base ::= numeral
4 based_numeral ::= extended_digit {[underline] extended_digit}
5 extended_digit ::= digit | A | B | C | D | E | F

Legality Rules

6 {base} The base (the numeric value of the decimal numeral preceding the first #) shall be at least two and at most sixteen. The extended_digits A through F represent the digits ten through fifteen, respectively. The value of each extended_digit of a based_literal shall be less than the base.

Static Semantics

7 The conventional meaning of based notation is assumed. An exponent indicates the power of the base by which the value of the based_literal without the exponent is to be multiplied to obtain the value of the based_literal with the exponent. The base and the exponent, if any, are in decimal notation.

8 The extended_digits A through F can be written either in lower case or in upper case, with the same meaning. 


9 Examples of based literals: 


2#1111_1111#  16#FF#       016#0ff#   --  integer literals of value 255
16#E#E1       2#1110_0000#            --  integer literals of value 224
16#F.FF#E+2   2#1.1111_1111_1110#E11  --  real literals of value 4095.0

Wording Changes from Ada 83

10.a The rule about which letters are allowed is now encoded in BNF, as suggested by Mike Woodger. This is clearly more readable.


Alexis Ada

With the use of a pragma, the user may authorize bases 2 to 36. Bases higher than 10 use the ASCII letters A to Z as required. The letter A represents 10, B represents 11, etc. up to Z that represents 35. The corresponding lowercase characters (a to z) represent the same values.


Syndicate content