Konvertuje hex číslo na dekadické
Delphi & Pascal (česká wiki)
Kategorija: Zadaňa zos Pascalu
Program: Hex.pas
Subor exe: Hex.exe
Program: Hex.pas
Subor exe: Hex.exe
Konvertuje hex číslo na dekadické.
{ HEX.PAS Copyright (c) TrSek alias Zdeno Sekerak } { Convert hex prezentation as string to long. } { } { Datum:13.07.2013 http://www.trsek.com } program HexConvert; var a: longint; cislo: string; { Convert hex prezentation as string to long } function HexToDec(S: string): Longint; var I : Integer; Result : Longint; begin Result := 0; for I := 1 to Length(S) do begin Result := 16*Result; if (S[I] >= '0') and (S[I] <= '9') then Result := Result + Ord(S[I]) - Ord('0') else if (S[I] >= 'A') and (S[I] <= 'F') then Result := Result + Ord(S[I]) - Ord('A') + 10 else if (S[I] >= 'a') and (S[I] <= 'f') then Result := Result + Ord(S[I]) - Ord('a') + 10 end; HexToDec := Result; end; { test it } begin write('Write hex : '); readln(cislo); a:= HexToDec(cislo); WriteLn('Integer is : ', a); ReadLn; end.