Консультация № 162568
17.03.2009, 13:44
0.00 руб.
0 1 1
Здравствуйте, уважаемые эксперты.
Нуждаюсь вашей помощи, в таком вопросе:
Есть почти сделанная программа. Программа преобразует слово в 10 систему, а потом из 10 в 2 систему. Потом идет шаг, преобразования наоборот, из 2 в 10, и из 10 в слово. проблема в том, что не могу понять, как из 10 системы преобразовать обратно слово. К сообщению прикрепляю саму программу, а также код.


Приложение:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button5: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Memo1: TMemo;
Memo2: TMemo;
Label5: TLabel;
Label6: TLabel;
Memo3: TMemo;
Memo4: TMemo;
Label7: TLabel;
Label8: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button5Click(Sender: TObject);


private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var

i,a:integer;
m1,m2:string;
begin
m1:=memo1.text;
m2:='';
for i:=1 to length(m1) do
begin
a:=ord(m1[i]);
m2:=m2+inttostr(a)+' ';
end;
memo2.Text:=m2;
end;



function IntToBin(d: LongInt): string;
var
x: Integer;
bin: string;
begin
bin := '';
for x := 1 to 8 * SizeOf(d) do
begin
if Odd(d) then bin := '1' + bin
else
bin := '0' + bin;
d := d shr 1;
end;
Delete(bin, 1, 8 * ((Pos('1', bin) - 1) div 8));
Result := bin;
end;



function BinToInt(Value: string): Integer;
var
i, iValueSize: Integer;
begin
Result := 0;
iValueSize := Length(Value);
for i := iValueSize downto 1 do
if Value[i] = '1' then Result := Result + (1 shl (iValueSize - i));
end;


procedure TForm1.Button3Click(Sender: TObject);
begin
close;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
m2: String;
i: integer;
begin
Memo3.Text:= '';
m2 := Memo2.Text;
for i := 1 to length(m2) do
begin
Memo3.Text:= Memo3.Text + IntToBin(ord(m2[i])) + ' ';
end;
end;

procedure TForm1.Button5Click(Sender: TObject);
var
slovo: String;
i: integer;
begin
Memo4.Text:= Memo3.Text;
memo4.Text:= '';
for i := 1 to length(memo3.Text) do
begin
if memo3.Text[i] <> ' ' then
slovo:= slovo + memo3.Text[i]
else
begin
memo4.Text:= memo4.Text + chr(BinToInt(slovo));
slovo:= '';
end;
end;
end;




end.

Обсуждение

Неизвестный
17.03.2009, 14:50
общий
это ответ
Здравствуйте, Kreaman!

procedure TForm1.Button4Click(Sender: TObject);
var
slovo : String;
i: integer;
begin
memo5.Text := '';
for i := 1 to length(memo4.Text) do
begin
if memo4.Text[i] <> ' ' then
slovo:= slovo + memo4.Text[i]
else
begin
memo5.Text := memo5.Text + chr(StrToInt(slovo));
slovo:= '';
end;
end;
end;
Форма ответа