Autor Beitrag
Boldar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1555
Erhaltene Danke: 70

Win7 Enterprise 64bit, Win XP SP2
Turbo Delphi
BeitragVerfasst: Sa 16.08.08 00:15 
Aus irgendeinem Grund gibt inttostr bei mir bei uint-Werten über 2^32 immer -1 Zurück. Es gibt leider kein inttostr64. Lässt sich dass irgenwie ändern?
wazup
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 101

Windows XP
Delphi 2009
BeitragVerfasst: Sa 16.08.08 01:37 
Die Funktion IntToStr wandelt nicht nur Integer in einen String um sondern auch Int64 :!:
ausblenden Delphi-Quelltext
1:
2:
  function IntToStr(Value: Integer): string;
  function IntToStr(Value: Int64): string;
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 16.08.08 01:56 
uint ist aber gar kein Int64... Das ist ein ganzzahliger Wert zwischen 0 und 4294967295. Und das funktioniert bei mir problemlos:
ausblenden Delphi-Quelltext
1:
  ShowMessage(IntToStr(Uint(4194967295)));					
Das ist 100000000 unter dem maximalen Wert für uint.
Mit Int64 gehen noch viel höhere Werte und auch mit IntToStr.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Sa 16.08.08 03:31 
@jaenicke: uint = uint32 = DWORD, uint64 != uint32: uint64 = Unsigned Int64 = Kann Delphi nicht über die Standard-Funktionen. Delphi behandelt Int64 IMMER mit Vorzeichen (Also Bit 63). Zahlen bis 2^63-1 sollte er also Problemlos darstellen.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Boldar Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1555
Erhaltene Danke: 70

Win7 Enterprise 64bit, Win XP SP2
Turbo Delphi
BeitragVerfasst: Sa 16.08.08 13:48 
aber wieso gibt inttostr bei mir für Werte über 2^32-1 dann eins Zurück??
Grenzgaenger
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 16.08.08 14:12 
macht doch gar nicht ...

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
program Project1;
{$APPTYPE CONSOLE}

uses
  SysUtils;

begin
 writeln(inttostr(MaxInt));
 readln;
end.


zeig doch mal deinem code her... habe meine kristallkugel in der firma ...
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Sa 16.08.08 14:15 
user profile iconBoldar hat folgendes geschrieben:
aber wieso gibt inttostr bei mir für Werte über 2^32-1 dann eins Zurück??

Lediglich eins?
DOH hat folgendes geschrieben:
When you increment the last value or decrement the first value of an integer type, the result wraps around the beginning or end of the range.
Boldar Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1555
Erhaltene Danke: 70

Win7 Enterprise 64bit, Win XP SP2
Turbo Delphi
BeitragVerfasst: Sa 16.08.08 14:20 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
Function IsPrim(zahl : Integer): boolean;
var
i: cardinal;
begin
  result := true;
  If zahl = 1 then
  begin
    result := false;
    exit;
  end;
  For i := 2 to Trunc(getsqrt(zahl))+1 do
  begin
    If ((zahl mod i) = 0) then
    begin
      result := false;
      exit;
    end;
  end;
end;



ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
procedure parse (a: tedit);
var s: string;
  s1: shortstring;
  aint : uint64;
begin
  s := a.text;
  if copy(s, 1, 1)='2' then
  begin
    if copy(s, 2, 1)='^' then
    begin
        s := copy (s, 3, length (s) -2);
        s1 := copy(s, 0, pos('-', s)-1);
        aint := strtoint64(s1);
        if aint > 62 then
        begin
          showmessage ('Zahl ist grösser als 2^62 und damit nicht zulässig');
          exit;
        end;
        aint := trunc(power (2, aint));
        aint := aint -1;
        s1 := inttostr(aint);
        showmessage (s1);
        a.Text := inttostr(aint);
    end;
  end;

end;


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm10.Button14Click(Sender: TObject);
var ant: cardinal;
begin
  uinttostr(00);
  parse (edit4);
  ant := strtoint(edit4.text);
  if isprim (ant) then showmessage (edit4.Text + ' ist eine Primzahl!') else showmessage (edit4.Text + ' ist keine Primzahl!')

end;




Mit dem Code sollen Zahlen in der Form 2^x -1 Auf Primzahlen untersuch werden!
Grenzgaenger
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 16.08.08 14:35 
du weisst aber schon... dass 2^32 etwas anderes ist als 2^64... :roll:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
var s: string;
  s1: shortstring;
  aint : uint64;
begin
  s := a.text;
  if copy(s, 1, 1)='2' then
  begin
    if copy(s, 2, 1)='^' then
    begin
        s := copy (s, 3, length (s) -2);
        s1 := copy(s, 0, pos('-', s)-1);
        aint := strtoint64(s1);
        if aint > 62 then
        begin
          showmessage ('Zahl ist grösser als 2^62 und damit nicht zulässig');
          exit;
        end;
        aint := trunc(power (2, aint));
wirbeldelphi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 29



BeitragVerfasst: Sa 16.08.08 15:19 
Wenn du Zahlen auf prim untersuchen willst und eh mit großen Zahlen umgehen willst solltest du nach Umsetzungen für den Miller-Rabin-Selfridge oder evtl. auch den Pollard-Rho Algorithmus suchen und auch nicht erst mit int64 rumdoktern sondern gleich auf units zugreifen die riesige Zahlen verarbeiten können. Siehe z.B. BigNum von BenBE.

Ist zwar am Thema inttostr vorbei, schickt dich aber in die richtige Richtung...

_________________
Ich bin keine Signatur - ich putz hier nur.