Non-decimal radices/Input: Difference between revisions
Content added Content deleted
(Add source for Rust) |
(add Pascal) |
||
Line 374: | Line 374: | ||
&B11010 = 26 |
&B11010 = 26 |
||
</pre> |
</pre> |
||
=={{header|Free Pascal}}== |
|||
Pascal, as defined in ISO 7185, only demands that ''decimal'' integers can be read with <tt>read</tt>/<tt>readLn</tt>. |
|||
As an extension, however, the implementation of <tt>read</tt>/<tt>readLn</tt>/<tt>readStr</tt> contained in the standard RTL (run-time library) shipped with FPC (Free Pascal Compiler) supports reading integers that meet the requirements of FreePascal’s own <tt>integer</tt> literal syntax. |
|||
Furthermore, <tt>0x</tt>/<tt>0X</tt> is recognized as a hexadecimal base indicator, although in source code it would be illegal. |
|||
<lang pascal> |
|||
program readIntegers(input, output); |
|||
var |
|||
i: aluSInt; |
|||
begin |
|||
while not EOF(input) do |
|||
begin |
|||
readLn(i); |
|||
writeLn(i:24); |
|||
end; |
|||
end. |
|||
</lang> |
|||
If the input is too large and cannot be stored in an <tt>integer</tt> (<tt>aluSInt</tt>), a run-time error is generated. |
|||
{{out}} |
|||
<pre> |
|||
$ cat << EOT | ./readIntegers |
|||
> -0 |
|||
> &0644 |
|||
> $cafeBabe |
|||
> 0xdeadBeef |
|||
> -0XfF |
|||
> -%1010 |
|||
> 1337 |
|||
> EOT |
|||
0 |
|||
420 |
|||
3735928559 |
|||
-255 |
|||
-10 |
|||
1337 |
|||
</pre> |
|||
Note, floating-point numbers, the data type <tt>real</tt>, can ''only'' be read in decimal notation. |
|||
The minus sign <tt>−</tt> (<tt>U+2212</tt>) is ''not'' recognized. |
|||
=={{header|Go}}== |
=={{header|Go}}== |
||
Line 749: | Line 788: | ||
{{works with|PARI/GP|2.8.0+}} |
{{works with|PARI/GP|2.8.0+}} |
||
<lang parigp>fromdigits([1,15,15],16)</lang> |
<lang parigp>fromdigits([1,15,15],16)</lang> |
||
=={{header|Pascal}}== |
|||
''See [[#Free Pascal|Free Pascal]]'' |
|||
=={{header|Perl}}== |
=={{header|Perl}}== |