سلام من سورس کدی میخوام که بتونه مبنای 10 به 2 و برعکس رو داشته باشه اگر کسی میتونه کمکم کنه چون خیلی مهم هست
سلام من سورس کدی میخوام که بتونه مبنای 10 به 2 و برعکس رو داشته باشه اگر کسی میتونه کمکم کنه چون خیلی مهم هست
Hex<>Bin<>Dec
5 تا Label
3 تا buton
و کد زیر
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, math;
type
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Edit2: TEdit;
Label2: TLabel;
Edit3: TEdit;
Label3: TLabel;
Button1: TButton;
Label4: TLabel;
Button2: TButton;
Label5: TLabel;
procedure calc(Sender: TObject);
procedure code(rem:int64; var s1:string; sender:TObject);
procedure hexto(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.calc(Sender: TObject);
var n,nn,dec,rem:int64;
s,s1,sbin,shex:string;
x:double;
begin
sbin:='';
s:=edit1.text;
n:=strtoint(s);
dec:=n;
repeat
x:=n/2;
nn:=trunc(x);
if (x-nn)=0.5 then s1:='1' else s1:='0';
sbin:=s1+sbin;
n:=nn;
until nn=0;
edit2.text:=sbin;
shex:='';
n:=dec;
repeat
x:=n/16;
nn:=trunc(x);
rem:=round(16*(x-nn));
code(rem,s1,sender);
shex:=s1+shex;
n:=nn
until nn=0;
Edit3.Text:=shex;
end;
procedure Tform1.code(rem:int64; var s1:string; sender:TObject);
begin
if rem<=9 then s1:=inttostr(rem) else begin
if rem=10 then s1:='A';
if rem=11 then s1:='B';
if rem=12 then s1:='C';
if rem=13 then s1:='D';
if rem=14 then s1:='E';
if rem=15 then s1:='F';
end;
end;
procedure decode(s: string; var num:integer);
begin
if s='0' then num:=0;
if s='1' then num:=1;
if s='2' then num:=2;
if s='3' then num:=3;
if s='4' then num:=4;
if s='5' then num:=5;
if s='6' then num:=6;
if s='7' then num:=7;
if s='8' then num:=8;
if s='9' then num:=9;
if s='A' then num:=10;
if s='B' then num:=11;
if s='C' then num:=12;
if s='D' then num:=13;
if s='E' then num:=14;
if s='F' then num:=15;
end;
procedure TForm1.hexto(Sender: TObject);
var hexstr,s:string;
n,nn,num:integer;
dec:int64;
begin
dec:=0;
hexstr:=edit3.text;
n:=length(hexstr);
for nn:=n downto 1 do begin
s:=copy(hexstr,nn,1);
decode(s,num);
dec:=dec+round(num*intpower(16,n-nn));
end;
edit1.text:=inttostr(dec);
calc(sender); {to get binary}
end;
end.
حالشو ببر
سلام
دستت درد نمننه یه روش دیگه پیدا کردم
سلام
بفرمایید :
کد:برای مشاهده محتوا ، لطفا وارد شوید یا ثبت نام کنید
هم اکنون 1 کاربر در حال مشاهده این تاپیک میباشد. (0 کاربر عضو شده و 1 مهمان)