Literals/Integer: Difference between revisions

Forth, BASE and prefixes
m (Put in lang learning cat)
(Forth, BASE and prefixes)
Line 65:
T
</pre>
 
=={{header|Forth}}==
The standard method for entering numbers of a particular base is to set the user variable BASE to the desired radix from 2 to 36. There are also convenience words for setting the base to DECIMAL and HEX.
<lang forth>
HEX
FEEDFACE
2 BASE !
1011001
DECIMAL
1234
: mask var @ [ base @ hex ] 3fff and [ base ! ] var ! ;
</lang>
The Forth numeric parser will look for symbols embedded within the stream of digits to determine whether to interpret it as a single cell, double cell, or floating point literal ('e').
<lang forth>
1234 ( n )
123.4 ( l h )
123e4 ( F: n )
</lang>
 
===Base prefixes===
{{works with|GNU Forth}}
In addition, many Forths have extensions for using a prefix to temporarily override BASE when entering an integer literal. These are the prefixes supported by GNU Forth.
<lang forth>
$feedface \ hexadecimal
&1234 \ decimal
%1001101 \ binary
'a \ base 256 (ASCII literal)
</lang>
Some Forths also support "0xABCD" hex literals for compatibility with C-like languages.
 
=={{header|Fortran}}==
Anonymous user