Convert Hexadecimal to Decimal (HexaDecimal ke Decimal)
Pada post sebelumnya saya telah menulis tentang Konversi Decimal ke Hexadecimal.Pada Post ini saya akan mengupas tentang fungsi untuk merubah Hexadecimal ke Decimal.
Berikut Adalah source codenya :
Fungsi Pendukung
Function Pangkat(Base : integer; exp: integer ): integer;
var i : integer;
begin
result:= 1;
for i := 1 to exp do
begin
result:=Result*Base;
end;
end;
Fungsi Utama
function HexToDec(Inp: String): String;
Var
I : Integer;
pwr : integer;
des : integer;
bil : Integer;
S: String;
Begin
Pwr:= length(Inp)-1;
des:=0;
For I := 0 to length(inp)-1 do
begin
S:= Copy(Inp,i+1,1);
if S='0' then Bil:= 0;
if S='1' then Bil:= 1;
if S='2' then Bil:= 2;
if S='3' then Bil:= 3;
if S='4' then Bil:= 4;
if S='5' then Bil:= 5;
if S='6' then Bil:= 6;
if S='7' then Bil:= 7;
if S='8' then Bil:= 8;
if S='9' then Bil:= 9;
if S='A' then Bil:= 10;
if S='B' then Bil:= 11;
if S='C' then Bil:= 12;
if S='D' then Bil:= 13;
if S='E' then Bil:= 14;
if S='F' then Bil:= 15;
des:= des + (Bil*pangkat(16,pwr));
dec(Pwr);
end;
Result:= IntToStr(Des);
end;
Untuk menggunakannya :
Var Hasil : String;
begin
.
.
Hasil:=HexToDec('AF');
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home