Bonjour !

J'ai commencé un programme qui convertit l'écriture décimale d'un nombre entier en écriture binaire, etc. Je sais bien qu'on trouve une multitude de programmes de ce genre (exemple). Je voudrais faire en Flash-Pascal ce qu'on fait d'ordinaire en PHP ou JavaScript.

Je suis embêté pour lui trouver un nom. J'ai lu quelque part le mot "convertisseur" mais mon dictionnaire n'est pas d'accord avec ce choix.

CONVERTISSEUR. s. m. Celui qui réussit dans la conversion des âmes. Ce missionnaire était un grand convertisseur.
Il signifie également, Celui qui s'efforce de convertir les autres à sa religion. Il est familier dans les deux sens et ne se dit guère que par plaisanterie.
Si vous avez une idée, je vous serais reconnaissant de m'en faire part.

En attendant, je l'ai appelé bases.

Critique bienvenue, car je voudrais faire quelque chose de propre pour ma première contribution aux sources Flash-Pascal.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
program Bases;
uses
  Flash8;
{$FRAME_WIDTH 240}
{$FRAME_HEIGHT 160}
{$BACKGROUND $A0A0A0}
type
  TEditBox = class(TextField)
    procedure onKeyDown;
  end;
var
  e: TEditBox;
  t1, t2, t3, t4: TextField;
  fmt: TextFormat;
 
function StrToInt(s: string): Integer;
  var
    i, tmp, p10: Integer;
  begin
    tmp := 0;
    p10 := 1;
    for i := Length(s) downto 1 do
      begin
        if (Ord(s[i]) >= 48) and (Ord(s[i]) <= 57) then
          begin
            Inc(tmp, (Ord(s[i])-48) * p10);
            p10 := p10 * 10;
          end;
      end;
    Result := tmp;
  end;
 
function IntToBase(i, base: Integer): string;
  var
    Digits, tmp: string;
  begin
    Digits := '0123456789ABCDEF';
    if i = 0 then
      tmp := '0'
    else
      tmp:='';
    while i > 0 do
      begin
        tmp := Digits [i mod base + 1] + tmp;
        i := i div base;
      end;
    Result := tmp;
  end;
 
procedure TEditBox.onKeyDown;
  var
    n: integer;
  begin
    if Key.getAscii = 13 then
    begin
      if Length(e.text) > 3 then
        Exit;
      n := StrToInt(e.text);
      t1.Text := IntToBase(n,  2);
      t2.Text := IntToBase(n,  8);
      t3.Text := IntToBase(n, 16);
    end;
  end;
 
procedure Encadre(xa, ya, l, h: Integer);
  begin
    _root.beginFill($ffffff);
    _root.lineStyle(2,$000080);
    _root.moveTo(xa    , ya);
    _root.lineTo(xa + l, ya);
    _root.lineTo(xa + l, ya + h);
    _root.lineTo(xa    , ya + h);
    _root.lineTo(xa    , ya)
  end;
 
begin
  fmt := TextFormat.Create('Tahoma', 14);
  fmt.color := $000000;
  Encadre(10, 10, 32, 21);
  Encadre(10, 38, 72, 21);
  Encadre(10, 66, 32, 21);
  Encadre(10, 94, 24, 21);
  e := TEditBox.Create(nil, 'input', 0, 10, 10 + 0 * (21 + 7), (3 + 1) * 8, 21);
  e.setNewTextFormat(fmt);
  e.type := 'input';
  e.text:='';
  Selection.setFocus(e);
  Key.addListener(e);
  t1:= TextField.Create(nil, 'output', 1, 10, 10 + 1 * (21 + 7), (8 + 1) * 8, 21);
  t2:= TextField.Create(nil, 'output', 2, 10, 10 + 2 * (21 + 7), (3 + 1) * 8, 21);
  t3:= TextField.Create(nil, 'output', 3, 10, 10 + 3 * (21 + 7), (2 + 1) * 8, 21);
  t4:= TextField.Create(nil, 'output', 4, 50, 10, 5 * 8, 21);
  t1.setNewTextFormat(fmt);
  t2.setNewTextFormat(fmt);
  t3.setNewTextFormat(fmt);
  t4.setNewTextFormat(fmt);
  t4.text := 'Byte';
end.