zoukankan      html  css  js  c++  java
  • Delphi版IP地址与整型互转

    Delphi版IP地址与整型互转

    unit Unit11;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;
    
    type
      TForm11 = class(TForm)
        edt1: TEdit;
        btn1: TButton;
        edt2: TEdit;
        btn2: TButton;
        procedure btn1Click(Sender: TObject);
        procedure btn2Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        function ip2Int(const strIP: string): Int64;
        function int2Ip(intIP: Int64): string;
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form11: TForm11;
    
    implementation
    
    {$R *.dfm}
    
    function TForm11.int2Ip(intIP : Int64) : string;
    var
      n : int64;
    begin
      Result := '';
      n := intIP shr 24;
      intIP := intIP xor (n shl 24);
      Result := IntToStr(n) + '.';
    
      n := intIP shr 16;
      intIP := intIP xor (n shl 16);
      Result := Result + IntToStr(n) + '.';
    
      n := intIP shr 8;
      intIP := intIP xor (n shl 8);
      Result := Result + IntToStr(n) + '.';
    
      n := intIP;
      Result := Result + IntToStr(n);
    end;
    
    function TForm11.ip2Int(const strIP : string): Int64;
    var
      lst : TStringList;
      i : integer;
    begin
      result := 0;
      lst := TStringList.Create;
      try
        lst.Delimiter := '.';
        lst.DelimitedText := strIP;
    
        for i := 0 to lst.Count - 1 do
          result := result + StrToInt64(lst[i]) shl (24 - i * 8);
      finally
        lst.Free;
      end;
    end;
    
    procedure TForm11.btn1Click(Sender: TObject);
    begin
      edt2.Text := IntToStr(ip2Int(edt1.Text));
    end;
    
    procedure TForm11.btn2Click(Sender: TObject);
    begin
      edt1.Text := int2Ip(StrToInt64(edt2.Text));
    end;
    
    procedure TForm11.FormCreate(Sender: TObject);
    begin
      edt1.Text := '192.168.1.1';
      btn1.Click;
    end;
    
    end.
  • 相关阅读:
    关于IDEA2019.3在书写pom依赖坐标无法自动提示补全的问题
    vue props的接收格式
    axios请求添加请求头 标准写法
    VUE后台管理系统建立
    arguments
    表单验证规则
    <<>> html内显示
    vue_UI组件库vant之加载转圈
    vue_axios请求拦截器
    vue_js数字有效长度16位_超出的解决办法
  • 原文地址:https://www.cnblogs.com/LittleTiger/p/5768263.html
Copyright © 2011-2022 走看看