C
cmdline
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
type
arr =array of char;
var
I,Temp :Integer;
J,NCount :Integer;
S :string;
arr1 :arr;
begin
S:=Edit1.Text;
I:=StrToInt(S);//
Temp:=I;//临时变量
NCount:=0;
ShowMessage(IntToHex(I,4));//转换为16进制
while I<>0 do
begin
I:=I div 2;
NCount:=NCount+1;
end;
SetLength(arr1,NCount-1);//建立动态数组
I:=Temp;
for J:=0 to NCount-1 do //开始转换二进制
begin
if (I mod 2)=1 then
arr1[NCount-J-1]:='1'
else
arr1[NCount-J-1]:='0';
I:=I div 2;
end;
s:='';
for Temp:=0 to NCount-1 do //输出二进制
S:=S+arr1[Temp];
Edit1.Text:=S;
end;
end.
上面这个程序完全通过,但是如果用整形数组,好像程序运行不了。
type
arr =array of integer;//改了这个
原程序在下面
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
type
arr =array of integer;
var
I,Temp :Integer;
J,NCount :Integer;
S :string;
arr1 :arr;
begin
S:=Edit1.Text;
I:=StrToInt(S);&#63729;
Temp:=I;
NCount:=0;
ShowMessage(IntToHex(I,4));
while I<>0 do
begin
I:=I div 2;
NCount:=NCount+1;
end;
SetLength(arr1,NCount-1);
I:=Temp;
for J:=0 to NCount-1 do
begin
if (I mod 2)=1 then
arr1[NCount-J-1]:=1
else
arr1[NCount-J-1]:=0;
I:=I div 2;
end;
s:='';
for Temp:=0 to NCount-1 do
S:=S+IntToStr(arr1[Temp]);
Edit1.Text:=S;
end;
end.
我还想问一下,有不有直接把二进制转换成十进制的函数和十进制转换成二进制的函数?
c语言和c++语言中的也行
我还想问一下,delphi中的记录类型想当于c语言和c++语言中的什麽类型?delphi的类又相当于他们中的什麽?
本人同时在学三门语言有很多地方不明白。恳请指教。上面的程序应该和可以简化,
谁可以在给出个优化算法
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
type
arr =array of char;
var
I,Temp :Integer;
J,NCount :Integer;
S :string;
arr1 :arr;
begin
S:=Edit1.Text;
I:=StrToInt(S);//&#63729;
Temp:=I;//临时变量
NCount:=0;
ShowMessage(IntToHex(I,4));//转换为16进制
while I<>0 do
begin
I:=I div 2;
NCount:=NCount+1;
end;
SetLength(arr1,NCount-1);//建立动态数组
I:=Temp;
for J:=0 to NCount-1 do //开始转换二进制
begin
if (I mod 2)=1 then
arr1[NCount-J-1]:='1'
else
arr1[NCount-J-1]:='0';
I:=I div 2;
end;
s:='';
for Temp:=0 to NCount-1 do //输出二进制
S:=S+arr1[Temp];
Edit1.Text:=S;
end;
end.
上面这个程序完全通过,但是如果用整形数组,好像程序运行不了。
type
arr =array of integer;//改了这个
原程序在下面
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
type
arr =array of integer;
var
I,Temp :Integer;
J,NCount :Integer;
S :string;
arr1 :arr;
begin
S:=Edit1.Text;
I:=StrToInt(S);&#63729;
Temp:=I;
NCount:=0;
ShowMessage(IntToHex(I,4));
while I<>0 do
begin
I:=I div 2;
NCount:=NCount+1;
end;
SetLength(arr1,NCount-1);
I:=Temp;
for J:=0 to NCount-1 do
begin
if (I mod 2)=1 then
arr1[NCount-J-1]:=1
else
arr1[NCount-J-1]:=0;
I:=I div 2;
end;
s:='';
for Temp:=0 to NCount-1 do
S:=S+IntToStr(arr1[Temp]);
Edit1.Text:=S;
end;
end.
我还想问一下,有不有直接把二进制转换成十进制的函数和十进制转换成二进制的函数?
c语言和c++语言中的也行
我还想问一下,delphi中的记录类型想当于c语言和c++语言中的什麽类型?delphi的类又相当于他们中的什麽?
本人同时在学三门语言有很多地方不明白。恳请指教。上面的程序应该和可以简化,
谁可以在给出个优化算法