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 ;
intIP := intIP xor (n shl );
Result := IntToStr(n) + '.'; n := intIP shr ;
intIP := intIP xor (n shl );
Result := Result + IntToStr(n) + '.'; n := intIP shr ;
intIP := intIP xor (n shl );
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 := ;
lst := TStringList.Create;
try
lst.Delimiter := '.';
lst.DelimitedText := strIP; for i := to lst.Count - do
result := result + StrToInt64(lst[i]) shl ( - i * );
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.

Delphi版IP地址与整型互转的更多相关文章

  1. PHP中IP地址与整型数字互相转换详解

    这篇文章主要介绍了PHP中IP地址与整型数字互相转换详解,本文介绍了使用PHP函数ip2long与long2ip的使用,以及它们的BUG介绍,最后给出自己写的两个算法,需要的朋友可以参考下 IP转换成 ...

  2. php IP string与整型互换

    PHP中有内置函数ip2long可以将ip地址转换整型. 使用long2ip把整型转换回ip地址 例子: $ip = '58.6.207.207'; $ip_int = ip2long($ip); e ...

  3. php 怎样将有范围的ip转化为整型范围

    php中将IP转换成整型的函数ip2long()容易出现问题,在IP比较大的情况下,会变成负数.如下: <?php $ip = "192.168.1.2"; $ip_n = ...

  4. Delphi 获取Ip地址的方法总结

    通过注册表获取或修改Ip 想到Windows会把系统网卡相关信息存入注册表,肯定可通过注册表读取具体ip信息.大致思路是找HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\W ...

  5. python字符串跟整型互转

    print ("整型:",int(50))a=int(50)print("整型:",a)numStr = "50";print (" ...

  6. [daily][python2] int型IP地址与string型IP地址互转

    使用python2,类似如下操作. >>> import socket >>> import struct >>> socket.ntohl(]) ...

  7. MySQL和PHP中以整型存储IP地址

    正文:将IP地址以整型存储 一般我们在数据库中会用到ip地址用来查记录的等等,而ip地址是分为四段的,一般是用varchar或char类型存储.但是其实有更好的存储方法就是以整型存储IP地址. 因为c ...

  8. MySQL存储IP地址操作

    数据库数据表创建语法: DROP TABLE IF EXISTS `admin`; CREATE TABLE IF NOT EXISTS `admin`( `adminid` INT UNSIGNED ...

  9. mysql 存储ip地址

    mysql提供了两个方法来处理ip地址: inet_aton 把ip转为无符号整型(4-8位) inet_ntoa 把整型的ip转为电地址 插入数据前,先用inet_aton把ip地址转为整型,可以节 ...

随机推荐

  1. Elasticsearch Java虚拟机配置详解(转)

    引言: 今天,事情终于发生了.Java6(Mustang),是2006年早些时候出来的,至今仍然应用在众多生产环境中,现在终于走到了尽头.已经没有什么理由阻止迁移到Java7(Dolphin)上了. ...

  2. ios UIApplication简单使用

    每个app有且只有一个UIApplication对象,当程序启动的时候通过调用UIApplicationMain方法得到的.可以通过sharedApplication方法得到. UIApplicati ...

  3. applicationhost.config web.config

    在 IIS7 8两个版本中, 用户的配置,可以通过修改如上的配置文件来完成 applicationhost.config ,可以定义全局的 用户自己目录下的web.config,可以自己定义 但是,有 ...

  4. 交互式shell和非交互式shell的区别

    交互式模式就是shell等待你的输入,并且执行你提交的命令.这种模式被称作交互式是因为shell与用户进行交互.这种模式也是大多数用户非常熟悉的:登录.执行一些命令.签退.当你签退后,shell也终止 ...

  5. HDU2629:Identity Card

    Problem Description Do you own an ID card?You must have a identity card number in your family's Hous ...

  6. 解决Xcode 9.2系统真机测试时出现 could not find developer disk image问题

    解决Xcode在ipad/iphone 9.2 系统真机测试时出现could not find developer disk image问题 第一种方法:拷贝这个文件(http://download. ...

  7. Ubuntu DNS bind9 配置

    下面的配置就是实现解析test.zp.com到不同的IP地址 安装dns server软件包$ apt-get install bind9 配置dns配置文件的路径在/etc/bind路径下面添加一个 ...

  8. hosts.deny 和hosts.allow 配置不生效

    需求:需要用hosts.deny限制用户通过ssh登录 在/etc/hosts.deny中加入 sshd: all 在/etc/hosts.allow中加入 sshd:all #拒绝所有的ip链接ss ...

  9. Inno Setup入门(十四)——替换安装程序和卸载程序的图标

    通常Inno生成的安装文件的图标是一个光盘和显示器,如下图.同时,程序安装好之后,在安装目录下的卸载程序的图标也是一样的,其实我们也可以自己修改. 首先生成的安装文件图标.这个比较简单,只需要在Set ...

  10. mongostat

    监控MongoDB有一下几种方法: 1)使用MongoDB软件包自带的工具,如mongostat,mongotop等.2)使用MongoDB数据库命令3)使用MongoDB公司提供的MMS监控服务 m ...