Non-decimal radices/Convert: Difference between revisions
Content added Content deleted
(→Joy: add) |
No edit summary |
||
Line 1,260: | Line 1,260: | ||
{{out}} |
{{out}} |
||
109517 |
109517 |
||
=={{header|Delphi}}== |
|||
{{works with|Delphi|6.0}} |
|||
{{libheader|SysUtils,StdCtrls}} |
|||
<syntaxhighlight lang="Delphi"> |
|||
function GetRadixString(L: Integer; Radix: Byte): string; |
|||
{Converts integer a string of any radix} |
|||
const RadixChars: array[0..35] Of char = |
|||
('0', '1', '2', '3', '4', '5', '6', '7', |
|||
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F', |
|||
'G','H', 'I', 'J', 'K', 'L', 'M', 'N', |
|||
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', |
|||
'W', 'X', 'Y', 'Z'); |
|||
var I: integer; |
|||
var S: string; |
|||
var Sign: string[1]; |
|||
begin |
|||
Result:=''; |
|||
If (L < 0) then |
|||
begin |
|||
Sign:='-'; |
|||
L:=Abs(L); |
|||
end |
|||
else Sign:=''; |
|||
S:=''; |
|||
repeat |
|||
begin |
|||
I:=L mod Radix; |
|||
S:=RadixChars[I] + S; |
|||
L:=L div Radix; |
|||
end |
|||
until L = 0; |
|||
Result:=Sign + S; |
|||
end; |
|||
procedure ShowRadixConvertion(Memo: TMemo); |
|||
var B,N: integer; |
|||
var S,RS: string; |
|||
begin |
|||
N:=6502; |
|||
for B:=2 to 23 do |
|||
begin |
|||
RS:=GetRadixString(N,B); |
|||
RS:=LowerCase(RS); |
|||
Memo.Lines.Add(Format('%5d -> base: %3D = %15S',[N,B,RS])); |
|||
end; |
|||
end; |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
6502 -> base: 2 = 1100101100110 |
|||
6502 -> base: 3 = 22220211 |
|||
6502 -> base: 4 = 1211212 |
|||
6502 -> base: 5 = 202002 |
|||
6502 -> base: 6 = 50034 |
|||
6502 -> base: 7 = 24646 |
|||
6502 -> base: 8 = 14546 |
|||
6502 -> base: 9 = 8824 |
|||
6502 -> base: 10 = 6502 |
|||
6502 -> base: 11 = 4981 |
|||
6502 -> base: 12 = 391a |
|||
6502 -> base: 13 = 2c62 |
|||
6502 -> base: 14 = 2526 |
|||
6502 -> base: 15 = 1dd7 |
|||
6502 -> base: 16 = 1966 |
|||
6502 -> base: 17 = 1588 |
|||
6502 -> base: 18 = 1214 |
|||
6502 -> base: 19 = i04 |
|||
6502 -> base: 20 = g52 |
|||
6502 -> base: 21 = efd |
|||
6502 -> base: 22 = d9c |
|||
6502 -> base: 23 = c6g |
|||
</pre> |
|||
=={{header|E}}== |
=={{header|E}}== |