Thema: Delphi Hex to Dezimal von Pi

Einzelnen Beitrag anzeigen

shmia

Registriert seit: 2. Mär 2004
5.508 Beiträge
 
Delphi 5 Professional
 
#8

Re: Hex to Dezimal von Pi

  Alt 8. Jun 2004, 15:27
Zitat von Nicolai1605:
An der Formel stimmt was nicht: (glaube ich )
Ich habe eine andere und bei dir steht 16^0 was eigentlich nicht geht!
Die Formel stimmt schon (glaube ich ).
Genauer gesagt ist sie:
Pi = 3 * 16^0 + 2 * 16^(-1) + 4 * 16^(-2) + 3 * 16^(-3) + 15 * 16^(-4) ...
Wobei:
16^0 = 1
16^(-1) = 1/16 (ein sechzehntel)
16^(-2) = 1/(16^2) = 1 / (16*16)
...
Es handelt sich dabei um ein Festkommaformat. Es lässt sich relativ leicht
in ein binäres Festkommaformat transformieren:
aaaa.bbbbccccddddeeee
0011.0010010000111111

Hier die Umwandlung in das Extended-Format
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  h : string;
  x, f : Extended;
  i : Integer;
begin
   f := 1.0;
   h := '3243F6A8885';
   x := 0.0;

   for i := 1 to Length(h) do
   begin
      x := x + f * StrToInt('$'+h[i]);
      f := f / 16.0;
   end;

   Caption := FloatToStr(x);
end;
Andreas
  Mit Zitat antworten Zitat