<?xml version="1.0"?>
<clause number="9.4.4.2" title="Integer literals">
  <paragraph>Integer literals are used to write values of types <keyword>int</keyword>, <keyword>uint</keyword>, <keyword>long</keyword>, and <keyword>ulong</keyword>. Integer literals have two possible forms: <keyword>decimal</keyword> and hexadecimal. <grammar_production><name><non_terminal where="9.4.4.2">integer-literal</non_terminal></name> :: <rhs><non_terminal where="9.4.4.2">decimal-integer-literal</non_terminal></rhs><rhs><non_terminal where="9.4.4.2">hexadecimal-integer-literal</non_terminal></rhs></grammar_production><grammar_production><name><non_terminal where="9.4.4.2">decimal-integer-literal</non_terminal></name> :: <rhs><non_terminal where="9.4.4.2">decimal-digits</non_terminal><non_terminal where="9.4.4.2">integer-type-suffix</non_terminal><opt/></rhs></grammar_production><grammar_production><name><non_terminal where="9.4.4.2">decimal-digit</non_terminal>s</name> :: <rhs><non_terminal where="9.4.4.2">decimal-digit</non_terminal></rhs><rhs><non_terminal where="9.4.4.2">decimal-digits</non_terminal><non_terminal where="9.4.4.2">decimal-digit</non_terminal></rhs></grammar_production><grammar_production><name><non_terminal where="9.4.4.2">decimal-digit</non_terminal></name> :: one of <rhs><terminal>0</terminal><terminal>1</terminal><terminal>2</terminal><terminal>3</terminal><terminal>4</terminal><terminal>5</terminal><terminal>6</terminal><terminal>7</terminal><terminal>8</terminal><terminal>9</terminal></rhs></grammar_production><grammar_production><name><non_terminal where="9.4.4.2">integer-type-suffix</non_terminal></name> :: one of <rhs><terminal>U  u  L  l  UL  Ul  uL  ul  LU  Lu  lU  lu  </terminal></rhs></grammar_production><grammar_production><name><non_terminal where="9.4.4.2">hexadecimal-integer-literal</non_terminal></name> :: <rhs><terminal>0x</terminal><non_terminal where="9.4.4.2">hex-digits</non_terminal><non_terminal where="9.4.4.2">integer-type-suffix</non_terminal><opt/></rhs><rhs><terminal>0X</terminal><non_terminal where="9.4.4.2">hex-digits</non_terminal><non_terminal where="9.4.4.2">integer-type-suffix</non_terminal><opt/></rhs></grammar_production><grammar_production><name><non_terminal where="9.4.4.2">hex-digit</non_terminal>s</name> :: <rhs><non_terminal where="9.4.4.2">hex-digit</non_terminal></rhs><rhs><non_terminal where="9.4.4.2">hex-digits</non_terminal><non_terminal where="9.4.4.2">hex-digit</non_terminal></rhs></grammar_production><grammar_production><name><non_terminal where="9.4.4.2">hex-digit</non_terminal></name> :: one of <rhs><terminal>0</terminal><terminal>1</terminal><terminal>2</terminal><terminal>3</terminal><terminal>4</terminal><terminal>5</terminal><terminal>6</terminal><terminal>7</terminal><terminal>8</terminal><terminal>9</terminal><terminal>A</terminal><terminal>B</terminal><terminal>C</terminal><terminal>D</terminal><terminal>E</terminal><terminal>F</terminal><terminal>a</terminal><terminal>b</terminal><terminal>c</terminal><terminal>d</terminal><terminal>e</terminal><terminal>f</terminal></rhs></grammar_production></paragraph>
  <paragraph>The type of an integer literal is determined as follows: <list><list_item> If the literal has no suffix, it has the first of these types in which its value can be represented: <keyword>int</keyword>, <keyword>uint</keyword>, <keyword>long</keyword>, <keyword>ulong</keyword>. </list_item><list_item> If the literal is suffixed by U or u, it has the first of these types in which its value can be represented: <keyword>uint</keyword>, <keyword>ulong</keyword>. </list_item><list_item> If the literal is suffixed by L or l, it has the first of these types in which its value can be represented: <keyword>long</keyword>, <keyword>ulong</keyword>. </list_item><list_item> If the literal is suffixed by UL, Ul, uL, ul, LU, Lu, lU, or lu, it is of type <keyword>ulong</keyword>. </list_item></list></paragraph>
  <paragraph>If the value represented by an integer literal is outside the range of the <keyword>ulong</keyword> type, a compile-time error occurs. </paragraph>
  <paragraph>
    <note>[Note: As a matter of style, it is suggested that &quot;L&quot; be used instead of &quot;l&quot; when writing literals of type <keyword>long</keyword>, since it is easy to confuse the letter &quot;l&quot; with the digit &quot;1&quot;. end note]</note>
  </paragraph>
  <paragraph>To permit the smallest possible <keyword>int</keyword> and <keyword>long</keyword> values to be written as <keyword>decimal</keyword> integer literals, the following two rules exist: <list><list_item> When a <non_terminal where="9.4.4.2">decimal-integer-literal</non_terminal> with the value 2147483648 (2<super>31</super>) and no <non_terminal where="9.4.4.2">integer-type-suffix</non_terminal> appears as the token immediately following a unary minus operator token (<hyperlink>14.6.2</hyperlink>), the result is a constant of type <keyword>int</keyword> with the value <unicode>8722</unicode>2147483648 (<unicode>8722</unicode>2<super>31</super>). In all other situations, such a <non_terminal where="9.4.4.2">decimal-integer-literal</non_terminal> is of type <keyword>uint</keyword>. </list_item><list_item> When a <non_terminal where="9.4.4.2">decimal-integer-literal</non_terminal> with the value 9223372036854775808 (2<super>63</super>) and no <non_terminal where="9.4.4.2">integer-type-suffix</non_terminal> or the <non_terminal where="9.4.4.2">integer-type-suffix</non_terminal> L or l appears as the token immediately following a unary minus operator token (<hyperlink>14.6.2</hyperlink>), the result is a constant of type <keyword>long</keyword> with the value <unicode>8722</unicode>9223372036854775808 (<unicode>8722</unicode>2<super>63</super>). In all other situations, such a <non_terminal where="9.4.4.2">decimal-integer-literal</non_terminal> is of type <keyword>ulong</keyword>. </list_item></list></paragraph>
</clause>
