Delphi IP地址转换


本文整理自网络,侵删。

 

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function HexToInt(str:string) : Int64;
var
i :Word;
value : Int64;
pos : Word;
begin
value:=0;
pos:=length(str);
for i:=1 to pos do
 begin
case str[i] of
'f','F':
value := value*16+15;
'e','E':
value := value*16+14;
'd','D':
value := value*16+13;
'c','C':
 value := value*16+12;
'b','B':
value := value*16+11;
'a','A':
value := value*16+10;
'0'..'9':
value := value*16+ord(str[i])-ord('0');
else
 result:=value;
exit;
end;
result:=value;
end;
end;

function GetHexIP(ip:string):string;
var
  strlist:TStringList;
  i:Integer;
  hexip:string;
begin
  hexip:=ip;
  strlist:=TStringList.Create;
  strlist.Delimiter:='.';
  strlist.DelimitedText:=ip;
  for i := 0 to strlist.Count - 1 do
  begin
    hexip:=hexip+IntToHex(StrToInt(strlist.Strings[i]),2);
  end;
  hexip:=IntToStr(HexToInt(hexip));
  Result :=hexip;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
  strlist:TStringList;
  i:Integer;
begin
  strlist:=TStringList.Create;
  strlist.Delimiter:='.';
  strlist.DelimitedText:=Edit1.Text;
  for i := 0 to strlist.Count - 1 do
  begin
    Edit2.Text:=Edit2.Text+IntToHex(StrToInt(strlist.Strings[i]),2);
  end;
  Edit2.Text:=Edit2.Text;
  Edit2.Text:=IntToStr(HexToInt(Edit2.Text));

end;

end.

相关阅读 >>

Delphi 实现程序 动态 类名

Delphi出现 no mapping for the unicode character exists in the target multi-byte code page 处理方法

Delphi之format函数

Delphi vcl 的 tpagecontrol 控件,实现对页签的拖动

Delphi 以bytes为单位获取文件大小

Delphi中使用android振动

Delphi 设置combobox组合框的高度方法总结

Delphi读取utf8格式ini及取得动态�热�

Delphi使用idhttp 获取 httpsurl内容

Delphi 查找指定目录,指定扩展名的所有文件名

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...