Non-decimal radices/Convert: Difference between revisions

Line 65:
 
=={{header|ALGOL 68}}==
===Built in===
{{works with|ALGOL 68|Standard - no extensions to language used}}
{{works with|ALGOL 68G|Any - tested with release mk15-0.8b.fc9.i386}}
The ''formatted transput'' in '''ALGOL 68''' uses the '''format''' type ('''mode''').
This '''format''' type has many similarities with modern ''regular expressions''
and can be used to convert '''string''' patterns to and from many of the
built in types ('''mode'''s) in ALGOL 68. Here is an example converting
a numbers base.
 
<lang algol>INT base = 16, from dec = 26;
BITS to bits;
 
FORMAT hex repr = $n(base)r2d$;
 
FILE f; STRING str;
 
associate(f, str);
putf(f, (hex repr, BIN from dec));
print(("Hex: ",str, new line));
 
reset(f);
getf(f, (hex repr, to bits));
print(("Int: ",ABS to bits, new line))</lang>
Output:
<pre>
Hex: 1a
Int: +26
</pre>
Note that the only conversions "officially" available are for the bases 2r, 4r, 8r
and 16r. But [[ALGOL 68G]] allows formatting for all numbers in the range 2r to 16r.
 
===Implement===
Handles signed and unsigned numbers from all bases.
 
{{trans|python}}
 
Line 119 ⟶ 153:
+256 => 100 => +256
</pre>
===Libraries===
As of February 2009 no open source libraries to do this task have been located.
 
=={{header|C++}}==
<lang cpp>#include <limits>