diff --git a/Doc/Sd1/languageFundamentals.xml b/Doc/Sd1/languageFundamentals.xml index 01ffd0caaef49003caef0af505e6f3bda8599bdc..311df6de18c5dfe1e97dd6ed66e9cee11c0ab1f8 100644 --- a/Doc/Sd1/languageFundamentals.xml +++ b/Doc/Sd1/languageFundamentals.xml @@ -2131,6 +2131,34 @@ Octal 35</screen></td> </informaltable> </figure> + <figure xml:id="sd1_fig_intChooseOutputRepresentation"> + <title>Choose your output representation</title> + + <informaltable border="1"> + <colgroup width="67%"/> + + <colgroup width="33%"/> + + <tr> + <th>Code</th> + + <th>Result</th> + </tr> + + <tr> + <td><programlisting language="java">System.out.println("35 as Binary (Base 2): " + Integer.toString(35, 2)); +System.out.println("35 as Ternary (Base 3): " + Integer.toString(35, 3)); +System.out.println("35 as Octal (Base 8): " + Integer.toString(35, 8)); +System.out.println("35 as Hexadecimal (Base 16): " + Integer.toString(35, 16));</programlisting></td> + + <td><screen>35 as Binary (Base 2): 100011 +35 as Ternary (Base 3): 1022 +35 as Octal (Base 8): 43 +35 as Hexadecimal (Base 16): 23</screen></td> + </tr> + </informaltable> + </figure> + <qandaset defaultlabel="qanda" xml:id="sd1_qanda_illegalOctalLiteral"> <title>Pretty may not be pretty</title> @@ -2157,11 +2185,12 @@ int a = 20, right aligning numbers thereby padding leading positions with zeros:</para> - <programlisting language="java">public static void main(String[] args) { + <programlisting language="none">public static void main(String[] args) { int a = 20, b = 03, - <emphasis role="bold">c = 09; // Compiler error: The literal 09 of type int is out of range</emphasis> + <emphasis role="bold">c = 09; </emphasis><emphasis role="red"><emphasis + role="bold">// Compiler error: The literal 09 of type int is out of range</emphasis></emphasis> System.out.println(a + " + " + b + " + " + c + " = " + (a + b + c)); }</programlisting> @@ -2181,8 +2210,9 @@ int a = 20, <answer> <para>Integer literals starting with <quote>0</quote> denote octal - representation. Since the octal system's set of digits is - {0,1,2,3,4,5,6,7} the value <quote>09</quote> is invalid.</para> + representation. The octal system's set of digits is + {0,1,2,3,4,5,6,7}. Therefore <quote>9</quote> is no valid + digit.</para> </answer> </qandaentry> </qandadiv>