将大整数转化成IP地址和把IP地址转化成大整数
来源:互联网 发布:侯佩岑情商评价知乎 编辑:程序博客网 时间:2024/04/27 15:17
#include <iostream>#include <vector>#include <string>using namespace std;typedef unsigned char uchar;void ulong2ip(unsigned int bignum){int mod_a = 0, num = 0, i = 0;int arr[8] = { 0 };while (bignum){mod_a = bignum % 16;arr[i++] = mod_a;bignum = bignum / 16;}for (num = 7; num>0; num--){cout << arr[num] << " ";printf("%x", arr[num]);}cout << endl;for (num = 7; num >0; num--, num--){cout << arr[num] * 16 + arr[num-1];if (num>1)cout << ".";}}void int2ipstr(unsigned int ip) { printf("%u.%u.%u.%u", (uchar)* ((char *)&ip + 3), (uchar)* ((char *)&ip + 2), (uchar)* ((char *)&ip + 1), (uchar)* ((char *)&ip + 0)); }string ValueToIP(const int& nValue){//数值转化为IP//没有格式检查//返回值就是结果char strTemp[20];sprintf_s(strTemp, "%d.%d.%d.%d",(nValue & 0xff000000) >> 24,(nValue & 0x00ff0000) >> 16,(nValue & 0x0000ff00) >> 8,(nValue & 0x000000ff));return string(strTemp);}unsigned int IPToValue(const string& strIP){//IP转化为数值//没有格式检查//返回值就是结果int a[4];string IP = strIP;string strTemp;size_t pos;size_t i = 3;do{pos = IP.find(".");if (pos != string::npos){strTemp = IP.substr(0, pos);a[i] = atoi(strTemp.c_str());i--;IP.erase(0, pos + 1);}else{strTemp = IP;a[i] = atoi(strTemp.c_str());break;}} while (1); //a[3]=atoi(strtok(IP,'.').c_str());<pre code_snippet_id="1647425" snippet_file_name="blog_20160414_1_5934077" name="code" class="cpp"> //a[2]=atoi(strtok(NULL,'.').c_str());
//a[1]=atoi(strtok(NULL,'.').c_str());
//<span style="font-family: Arial, Helvetica, sans-serif;">a[0]=atoi(strtok(NULL,'\0').c_str());</span>
0 0
- 将大整数转化成IP地址和把IP地址转化成大整数
- IP地址转化成整数
- IP地址转化成整数
- 将IP地址转化为一个整数
- ip地址转化为整数 整数转化为IP地址
- MFC中,将IP地址转化为整数
- IP地址转换为一个整数和整数转化为IP地址
- js将ip地址转换成整数
- IP地址字符串与整数的互相转化
- 整数ip地址转化为01二进制表示...
- php ip转化成负整数
- 用C把整数转换成Ip地址
- ip地址和整数转换
- ip地址和整数转换
- 整数和IP地址转换
- 一个将u_long型的IP地址转化成字符串形式的IP地址方法
- ruby将ip地址转换成整数的方法
- Java将ip地址转换成整数的代码
- Spring中拦截/和拦截/*的区别 - 不能访问到返回的JSP - 访问静态资源(jpg,js等)
- oracle中的decode的使用
- RecyclerView中的坑RecyclerView$LayoutManager.stopSmoothScroller()报错
- 使用System.arraycopy()实现数组之间的复制
- spark.streaming.concurrentJobs参数分析
- 将大整数转化成IP地址和把IP地址转化成大整数
- tomcat配置文件server.xml详解
- 1011
- VC维的来龙去脉
- 172. Factorial Trailing Zeroes
- 禁止viewPager滑动事件 viewPager的重写套用
- 前端开发必须知道的JS(一) 原型和继承
- 阶乘
- Android API Guides---Processes and Threads