Başlangıç > Kodlar > Delphi ile HexToDec, DecToHex, üst hesaplama fonksiyonları

Delphi ile HexToDec, DecToHex, üst hesaplama fonksiyonları

16 lık tabandan 10 luk tabana ve 10 luk tabandan 16 lık tabana dönüşüm yapan fonksiyonlar

// üst hesaplama fonksiyonu
--------------------------------------------------
function ust_hesapla(sayi, ust:integer):integer;
var
k,sonuc:integer;
begin
if ust=0 then
begin
ust_hesapla:=1;
exit;
end;
sonuc:=1;
for k:=1 to ust do
sonuc:=sonuc*sayi;
ust_hesapla:=sonuc;
end;
---------------------------------------------------------
kullanımı ust:=ust_hesapla(2,2); // sonuc 4 döndürür.
---------------------------------------------------------

// hextodec fonksiyonu
---------------------------------------------------------
function hextodec(st:string):int64;
var
k,us,carpan:integer;
sonuc:=int64;
begin
us:=length(st)-1;
sonuc:=0;
for k:=1 to length(st) do
begin
case st[k] of
'1','2','3','4','5','6','7','8','9':carpan:=strtoint(st[k]);
'A':carpan:=10;
'B':carpan:=11;
'C':carpan:=12;
'D':carpan:=13;
'E':carpan:=14;
'F':carpan:=15;
end;
sonuc:=sonuc+carpan*ust_hesapla(16,us);
end;
hextodec:=sonuc;
end;
------------------------------------------------------------
kullanımı decsayi:=hextodec('41');  // sonuc 65 döndürür.
------------------------------------------------------------

// dectohex fonksiyonu
------------------------------------------------------------
function dectohex(sayi:int64):string;
var
sdizi:array[0..15] of char=('1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
bolum:int64;
st1:string;
kalan:integer;
begin
bolum:=sayi;
repeat
kalan:=bolum mod 16;
bolum:=(bolum-kalan) div 16;
if bolum<16 then
st1:=st1 + sdizi[bolum];
st1:=st1+sdizi[kalan];
until bolum<16;
dectohex:=st1;
end;
-------------------------------------------------------------
kullanımı strhex:=dectohex(65);  sonuc 41 döndürür.
-------------------------------------------------------------


TD Software


  1. Henüz yorum yapılmamış.
  1. No trackbacks yet.

Yorum bırakın