Thema: Delphi Ranges

Einzelnen Beitrag anzeigen

Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.549 Beiträge
 
Delphi 11 Alexandria
 
#6

Re: Ranges

  Alt 18. Apr 2008, 16:40
Hier mal eine Schmalspurversion ohne Fehlerbehandlung:
Delphi-Quellcode:
function IPToCardinal(IP: string): Cardinal;
var s: string;
begin
  //1. Oktett
  s := Copy(IP,1,Pos('.',IP) - 1);
  Delete(IP,1,Length(s) + 1);
  Result := StrToInt(s) shl 24;
  //2. Oktett
  s := Copy(IP,1,Pos('.',IP) - 1);
  Delete(IP,1,Length(s) + 1);
  Result := Result or (StrToInt(s) shl 16);
  //3. Oktett
  s := Copy(IP,1,Pos('.',IP) - 1);
  Delete(IP,1,Length(s) + 1);
  Result := Result or (StrToInt(s) shl 8);
  //4. Oktett (=Rest)
  Result := Result or StrToInt(IP);
end;

function CardinalToIP(const c: Cardinal): string;
begin
  Result := Format('%d.%d.%d.%d',[HiByte(HiWord(c)),LoByte(HiWord(c)),
                                  HiByte(LoWord(c)),LoByte(LoWord(c))]);
end;
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat