Non-decimal radices/Output: Difference between revisions

Added F# information
m (added whitespace before the TOC, added a ;Task; (bold) header.)
(Added F# information)
Line 401:
printf(1,"%6d %6x %6o\n",{i,i,i})
end for</lang>
 
=={{header|F_Sharp|F#}}==
<p>Base 8, 10 and 16 can be output by <code>printf</code></p>
<lang fsharp>let ns = [30..33]
ns |> Seq.iter (fun n -> printfn " %3o %2d %2X" n n n)</lang>
{{out}}
<pre> 36 30 1E
37 31 1F
40 32 20
41 33 21</pre>
<p>The .NET library <code>System.Convert</code> is able to also convert from and to base 2</p>
<lang fsharp>let bases = [2; 8; 10; 16]
 
ns |> Seq.map (fun n -> Seq.initInfinite (fun i -> n))
|> Seq.map (fun s -> Seq.zip s bases)
|> Seq.map (Seq.map System.Convert.ToString >> Seq.toList)
|> Seq.iter (fun s -> (printfn "%6s %2s %2s %2s" s.[0] s.[1] s.[2] s.[3]))</lang>
{{out}}
<pre> 11110 36 30 1e
11111 37 31 1f
100000 40 32 20
100001 41 33 21</pre>
 
=={{header|Factor}}==
Anonymous user